JuliaLang/julia — pull request #2755 by stevengj (2013-04-04 15:08:44+00:00)
Title: RFC: change jlapi (external C API) to Python-like exception-passing style

The current `jlapi.c` functions, which were initially written to call Julia from Python and more generally could be used to embed Julia in other programs, either do not catch exceptions or (in the case of `jl_eval_string`) catch exceptions and return them *instead* of the ordinary return value. This means if the caller (e.g. Python) calls a Julia routine that throws an exception, we either get an unhandled exception error or we cannot distinguish an exception from a routine that returns an `Exception` object.

This patch changes the `jlapi.c` functions to work more like the Python C API. API functions catch exceptions and return a sentinel value (e.g. `NULL` or `-1`) to indicate than an exception has occurred. A separate `jl_exception_occurred` function can then be called to retrieve the actual exception object.

cc: @fperez