Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
74d0302e
Commit
74d0302e
authored
Apr 13, 2010
by
Christopher Wedgwood
Committed by
Andrew Gerrand
Apr 13, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove exp/exception as it's no longer relevant
R=gri, adg CC=golang-dev, r, rsc
https://golang.org/cl/857048
parent
c701c38e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
156 deletions
+0
-156
Makefile
src/pkg/Makefile
+0
-1
Makefile
src/pkg/exp/exception/Makefile
+0
-11
exception.go
src/pkg/exp/exception/exception.go
+0
-83
exception_test.go
src/pkg/exp/exception/exception_test.go
+0
-61
No files found.
src/pkg/Makefile
View file @
74d0302e
...
...
@@ -67,7 +67,6 @@ DIRS=\
exp/datafmt
\
exp/draw
\
exp/eval
\
exp/exception
\
exp/iterable
\
expvar
\
flag
\
...
...
src/pkg/exp/exception/Makefile
deleted
100644 → 0
View file @
c701c38e
# 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
src/pkg/exp/exception/exception.go
deleted
100644 → 0
View file @
c701c38e
// 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
""
}
src/pkg/exp/exception/exception_test.go
deleted
100644 → 0
View file @
c701c38e
// 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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment