Skip to content

Commit 8234f5b

Browse files
committed
Make ExceptionInfo which is Type, Value, Traceback for panic propagation
1 parent 778850d commit 8234f5b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎py/exception.go‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ type Exception struct{
1717
OtherStringDict// anything else that we want to stuff in
1818
}
1919

20+
// A python exception info block
21+
typeExceptionInfostruct{
22+
TypeObject
23+
ValueObject
24+
TracebackObject
25+
}
26+
27+
// Make Exception info statisfy the error interface
28+
2029
var (
2130
// Exception heirachy
2231
BaseException=ObjectType.NewTypeFlags("BaseException", "Common base class for all exceptions", ExceptionNew, nil, ObjectType.Flags|TPFLAGS_BASE_EXC_SUBCLASS)
@@ -94,6 +103,14 @@ func (e *Exception) Error() string{
94103
returnfmt.Sprintf("%s: %v", e.Base.Name, e.Args)
95104
}
96105

106+
// Go error interface
107+
func (eExceptionInfo) Error() string{
108+
ifexception, ok:=e.Value.(*Exception); ok{
109+
returnexception.Error()
110+
}
111+
returne.Value.Type().Name
112+
}
113+
97114
// ExceptionNew
98115
funcExceptionNew(metatype*Type, argsTuple, kwargsStringDict) Object{
99116
iflen(kwargs) !=0{
@@ -136,7 +153,7 @@ func ExceptionNewf(metatype *Type, format string, a ...interface{}) *Exception{
136153
}
137154
*/
138155

139-
// Coerce an object into an exception one way or another
156+
// Coerce an object into an exception instance one way or another
140157
funcMakeException(rinterface{}) *Exception{
141158
switchx:=r.(type){
142159
case*Exception:
@@ -238,3 +255,4 @@ func ExceptionGivenMatches(err, exc Object) bool{
238255

239256
// Check Interfaces
240257
var_error= (*Exception)(nil)
258+
var_error= (*ExceptionInfo)(nil)

0 commit comments

Comments
(0)