File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 8
8
# print(ex.__traceback__)
9
9
# print(type(ex.__traceback__))
10
10
11
+ try :
12
+ raise ZeroDivisionError
13
+ except ZeroDivisionError as ex :
14
+ pass
15
+
16
+ class E (Exception ):
17
+ def __init__ (self ):
18
+ asdf
19
+
20
+ try :
21
+ raise E
22
+ except NameError as ex :
23
+ pass
11
24
12
25
l = []
13
26
try :
Original file line number Diff line number Diff line change @@ -515,6 +515,12 @@ impl Frame {
515
515
if objtype:: isinstance ( & exception, & vm. ctx . exceptions . base_exception_type ) {
516
516
info ! ( "Exception raised: {:?}" , exception) ;
517
517
Err ( exception)
518
+ } else if objtype:: isinstance ( & exception, & vm. ctx . type_type ( ) )
519
+ && objtype:: issubclass ( & exception, & vm. ctx . exceptions . base_exception_type )
520
+ {
521
+ let exception = vm. new_empty_exception ( exception) ?;
522
+ info ! ( "Exception raised: {:?}" , exception) ;
523
+ Err ( exception)
518
524
} else {
519
525
let msg = format ! (
520
526
"Can only raise BaseException derived types, not {}" ,
Original file line number Diff line number Diff line change @@ -107,7 +107,17 @@ impl VirtualMachine {
107
107
self . ctx . new_dict ( )
108
108
}
109
109
110
+ pub fn new_empty_exception ( & mut self , exc_type : PyObjectRef ) -> PyResult {
111
+ info ! ( "New exception created: no msg" ) ;
112
+ let args = PyFuncArgs {
113
+ args : vec ! [ ] ,
114
+ kwargs : vec ! [ ] ,
115
+ } ;
116
+ self . invoke ( exc_type, args)
117
+ }
118
+
110
119
pub fn new_exception ( & mut self , exc_type : PyObjectRef , msg : String ) -> PyObjectRef {
120
+ // TODO: exc_type may be user-defined exception, so we should return PyResult
111
121
// TODO: maybe there is a clearer way to create an instance:
112
122
info ! ( "New exception created: {}" , msg) ;
113
123
let pymsg = self . new_str ( msg) ;
You can’t perform that action at this time.
0 commit comments