Thanks for the quick feedback.
I managed to get C++ exception handling working in Cxx, after some back and
forth experimentation.
In the end, I added the following to bootstrap.cpp:
// Enable C++ exception handling
clang_compiler->getLangOpts().Exceptions = 1; // exception
handling
clang_compiler->getLangOpts().ObjCExceptions = 1; // Objective-C
exceptions
clang_compiler->getLangOpts().CXXExceptions = 1; // C++ exceptions
However, note that you may NOT add SjLjExceptions at least on OSX (at least
not without further changes):
clang_compiler->getLangOpts().SjLjExceptions = 1; // setjmp-longjump
exception handling
The latter produced the following ERROR after using a simple "throw" test
code (see below):
LLVM ERROR: Program used external function '___gxx_personality_sj0' which
could not be resolved!
I then rebuilt libcxxffi.dylib with Pkg.build("Cxx") and tested the same
zeroDivExceptionTest C++ script:
julia> cxx"""
#include <iostream> //std::cerr
const int ZeroDivisionError = 1;
double divide(double x, double y)
{
if(y==0)
{
throw ZeroDivisionError;
}
return x/y;
}
void zeroDivExceptionTest(double a, double b)
{
try
{
double c = divide(a, b);
std::cout<<"Result is: " << c <<std::endl;
}
catch(int i)
{
if(i==ZeroDivisionError)
{
std::cerr<< "Divide by zero error!" <<std::endl;
}
}
}
"""
julia> @cxx zeroDivExceptionTest(5.0, 0)
Divide by zero error!
julia> @cxx zeroDivExceptionTest(1.0, 5.0)
Result is: 0.2
julia> @cxx zeroDivExceptionTest(43.3, 0)
Divide by zero error!