@@ -257,6 +257,7 @@ def __init__(self, init_julia=True, jl_init_path=None):
257257 self .api .jl_typename_str .restype = char_p
258258 self .api .jl_typeof_str .restype = char_p
259259 self .api .jl_unbox_voidpointer .restype = py_object
260+ self .api .jl_bytestring_ptr .restype = char_p
260261
261262 if init_julia :
262263 try :
@@ -295,13 +296,22 @@ def call(self, src):
295296 # return null ptr if error
296297 ans = self .api .jl_eval_string (src .encode ('utf-8' ))
297298 if not ans :
298- jexp = self .api . jl_exception_occurred ( )
299- exception_str = self ._unwrap_exception ( jexp ).decode ('utf-8' )
300- raise JuliaError (u'Exception calling julia src: {} \n {}'
301- .format (exception_str , src ))
299+ exception_type = self ._typeof_julia_exception_in_transit (). decode ( 'utf-8' )
300+ exception_msg = self ._capture_showerror_for_last_julia_exception ( ).decode ('utf-8' )
301+ raise JuliaError (u'Exception \' {} \' ocurred while calling julia code: \n {} \n \n Code: \n {}'
302+ .format (exception_type , exception_msg , src ))
302303 return ans
303304
304- def _unwrap_exception (self , jl_exc ):
305+ def _capture_showerror_for_last_julia_exception (self ):
306+ msg = self .api .jl_eval_string (u"""
307+ try
308+ rethrow()
309+ catch ex
310+ sprint(showerror, ex, catch_backtrace())
311+ end""" )
312+ return char_p (msg ).value .encode ("utf-8" )
313+
314+ def _typeof_julia_exception_in_transit (self ):
305315 exception = void_p .in_dll (self .api , 'jl_exception_in_transit' )
306316 msg = self .api .jl_typeof_str (exception )
307317 return char_p (msg ).value
0 commit comments