diff options
author | Christopher Wedgwood <cw@f00f.org> | 2010-04-13 10:51:35 +1000 |
---|---|---|
committer | Christopher Wedgwood <cw@f00f.org> | 2010-04-13 10:51:35 +1000 |
commit | ad25374290ae4a3bb3772d8b58ef0dfeb443a8ce (patch) | |
tree | 68f81b2ae86b8355ce17b402f4c1ad58a7eb0da0 /src/pkg/exp/exception/exception.go | |
parent | 929efc17e2d4086afc1957b1b2f8b47d0d16d54f (diff) | |
download | golang-ad25374290ae4a3bb3772d8b58ef0dfeb443a8ce.tar.gz |
Remove exp/exception as it's no longer relevant
R=gri, adg
CC=golang-dev, r, rsc
http://codereview.appspot.com/857048
Committer: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/pkg/exp/exception/exception.go')
-rw-r--r-- | src/pkg/exp/exception/exception.go | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/src/pkg/exp/exception/exception.go b/src/pkg/exp/exception/exception.go deleted file mode 100644 index e34d0f0d7..000000000 --- a/src/pkg/exp/exception/exception.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// This package illustrates how basic try-catch exception handling -// can be emulated using goroutines, channels, and closures. -// -// This package is *not* intended as a general exception handler -// library. -// -package exception - -import ( - "fmt" - "runtime" -) - -// A Handler function handles an arbitrary exception value x. -type Handler func(x interface{}) - -// An Exception carries an exception value. -type Exception struct { - Value interface{} // Value may be the nil exception -} - -// Try invokes a function f with a Handler to throw exceptions. -// The function f may terminate abnormally with an arbitrary -// exception x by calling throw(x) within f. If an exception is -// thrown, Try returns an *Exception; otherwise it returns nil. -// -// Usage pattern: -// -// if x := exception.Try(func(throw exception.Handler) { -// ... -// throw(42); // terminate f by throwing exception 42 -// ... -// }); x != nil { -// // catch exception, e.g. print it -// fmt.Println(x.Value); -// } -// -// Alternative: -// -// exception.Try(func(throw exception.Handler) { -// ... -// throw(42); // terminate f by throwing exception 42 -// ... -// }).Catch(func (x interface{}) { -// // catch exception, e.g. print it -// fmt.Println(x); -// }) -// -func Try(f func(throw Handler)) *Exception { - h := make(chan *Exception) - - // execute try block - go func() { - f(func(x interface{}) { - h <- &Exception{x} - runtime.Goexit() - }) - h <- nil // clean termination - }() - - return <-h -} - - -// If x != nil, Catch invokes f with the exception value x.Value. -// See Try for usage patterns. -func (x *Exception) Catch(f Handler) { - if x != nil { - f(x.Value) - } -} - - -func (x *Exception) String() string { - if x != nil { - return fmt.Sprintf("exception: %v", x.Value) - } - return "" -} |