aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Wedgwood <cw@f00f.org>2010-04-13 10:51:35 +1000
committerAndrew Gerrand <adg@golang.org>2010-04-13 10:51:35 +1000
commit74d0302eb9c4f5fd2b771a0c1798d3ead3254826 (patch)
tree529247fa42e829fdcb87ef297eb0a6f544d26d50
parentc701c38e136576b75ec771c311d66c19c149b386 (diff)
downloadgo-74d0302eb9c4f5fd2b771a0c1798d3ead3254826.tar.gz
go-74d0302eb9c4f5fd2b771a0c1798d3ead3254826.zip
Remove exp/exception as it's no longer relevant
R=gri, adg CC=golang-dev, r, rsc https://golang.org/cl/857048
-rw-r--r--src/pkg/Makefile1
-rw-r--r--src/pkg/exp/exception/Makefile11
-rw-r--r--src/pkg/exp/exception/exception.go83
-rw-r--r--src/pkg/exp/exception/exception_test.go61
4 files changed, 0 insertions, 156 deletions
diff --git a/src/pkg/Makefile b/src/pkg/Makefile
index d7365bfd9e..4057ed97d1 100644
--- a/src/pkg/Makefile
+++ b/src/pkg/Makefile
@@ -67,7 +67,6 @@ DIRS=\
exp/datafmt\
exp/draw\
exp/eval\
- exp/exception\
exp/iterable\
expvar\
flag\
diff --git a/src/pkg/exp/exception/Makefile b/src/pkg/exp/exception/Makefile
deleted file mode 100644
index 19c86630f0..0000000000
--- a/src/pkg/exp/exception/Makefile
+++ /dev/null
@@ -1,11 +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.
-
-include ../../../Make.$(GOARCH)
-
-TARG=exp/exception
-GOFILES=\
- exception.go\
-
-include ../../../Make.pkg
diff --git a/src/pkg/exp/exception/exception.go b/src/pkg/exp/exception/exception.go
deleted file mode 100644
index e34d0f0d76..0000000000
--- 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 ""
-}
diff --git a/src/pkg/exp/exception/exception_test.go b/src/pkg/exp/exception/exception_test.go
deleted file mode 100644
index b7b106d776..0000000000
--- a/src/pkg/exp/exception/exception_test.go
+++ /dev/null
@@ -1,61 +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.
-
-package exception
-
-import "testing"
-
-func TestNoException(t *testing.T) {
- e := Try(func(throw Handler) {})
- if e != nil {
- t.Fatalf("no exception expected, found: %v", e)
- }
-}
-
-
-func TestNilException(t *testing.T) {
- e := Try(func(throw Handler) { throw(nil) })
- if e == nil {
- t.Fatalf("exception expected", e)
- }
- if e.Value != nil {
- t.Fatalf("nil exception expected, found: %v", e)
- }
-}
-
-
-func TestTry(t *testing.T) {
- s := 0
- for i := 1; i <= 10; i++ {
- e := Try(func(throw Handler) {
- if i%3 == 0 {
- throw(i)
- panic("throw returned")
- }
- })
- if e != nil {
- s += e.Value.(int)
- }
- }
- result := 3 + 6 + 9
- if s != result {
- t.Fatalf("expected: %d, found: %d", result, s)
- }
-}
-
-
-func TestCatch(t *testing.T) {
- s := 0
- for i := 1; i <= 10; i++ {
- Try(func(throw Handler) {
- if i%3 == 0 {
- throw(i)
- }
- }).Catch(func(x interface{}) { s += x.(int) })
- }
- result := 3 + 6 + 9
- if s != result {
- t.Fatalf("expected: %d, found: %d", result, s)
- }
-}