@@ -154,7 +154,6 @@ public static void Initialize(IEnumerable<string> args)
154154 Exceptions . Clear ( ) ;
155155
156156 Py . SetArgv ( args ) ;
157- Py . Throw ( ) ;
158157
159158 // register the atexit callback (this doesn't use Py_AtExit as the C atexit
160159 // callbacks are called after python is fully finalized but the python ones
@@ -382,10 +381,7 @@ public static void EndAllowThreads(IntPtr ts)
382381 public static PyObject ImportModule ( string name )
383382 {
384383 IntPtr op = Runtime . PyImport_ImportModule ( name ) ;
385- if ( op == IntPtr . Zero )
386- {
387- return null ;
388- }
384+ Py . Throw ( ) ;
389385 return new PyObject ( op ) ;
390386 }
391387
@@ -401,10 +397,7 @@ public static PyObject ImportModule(string name)
401397 public static PyObject ReloadModule ( PyObject module )
402398 {
403399 IntPtr op = Runtime . PyImport_ReloadModule ( module . Handle ) ;
404- if ( op == IntPtr . Zero )
405- {
406- throw new PythonException ( ) ;
407- }
400+ Py . Throw ( ) ;
408401 return new PyObject ( op ) ;
409402 }
410403
@@ -420,15 +413,9 @@ public static PyObject ReloadModule(PyObject module)
420413 public static PyObject ModuleFromString ( string name , string code )
421414 {
422415 IntPtr c = Runtime . Py_CompileString ( code , "none" , ( IntPtr ) 257 ) ;
423- if ( c == IntPtr . Zero )
424- {
425- throw new PythonException ( ) ;
426- }
416+ Py . Throw ( ) ;
427417 IntPtr m = Runtime . PyImport_ExecCodeModule ( name , c ) ;
428- if ( m == IntPtr . Zero )
429- {
430- throw new PythonException ( ) ;
431- }
418+ Py . Throw ( ) ;
432419 return new PyObject ( m ) ;
433420 }
434421
@@ -476,10 +463,7 @@ public static PyObject RunString(
476463 code , flag , globals . Value , locals . Value
477464 ) ;
478465
479- if ( Runtime . PyErr_Occurred ( ) != 0 )
480- {
481- throw new PythonException ( ) ;
482- }
466+ Py . Throw ( ) ;
483467
484468 return new PyObject ( result ) ;
485469 }
@@ -583,6 +567,7 @@ public static void SetArgv(IEnumerable<string> argv)
583567 {
584568 var arr = argv . ToArray ( ) ;
585569 Runtime . PySys_SetArgvEx ( arr . Length , arr , 0 ) ;
570+ Py . Throw ( ) ;
586571 }
587572 }
588573
0 commit comments