Hi
I am not very familiar with the mechanics of exception handling in Clang
and I realize that exceptions (throw/catch) work well in Julia itself.
However, I am specifically trying to use exception handling in C++ code
nested inside Julia with Cxx.jl. I noticed exception handling is meant to
be switched off by default in Clang, but still it seems to me that it would
be very useful to have it switched on when dealing with GUI applications.
I tried several C++ exceptions (e.g., throw/catch, std::exception) but it
seems they are disabled in my current Julia-v0.4.0-dev build (OSX 10.9.5).
Since I did not use the -fno-exceptions flag to build Julia, I wonder
why/where exceptions are switched off when I built Julia.
In Xcode(with libc++-LLVM, C++11), I can run the following script with C++
exceptions and it works:
const int ZeroDivisionError = 1;
double divide(double x, double y)
{
if(y==0)
{
throw ZeroDivisionError;
}
return x/y;
}
int main()
{
try
{
divide(1, 0);
}
catch(int i)
{
if(i==ZeroDivisionError)
{
std::cerr<<"Divide by zero error";
}
}
}
*Divide by zero error *Program ended with exit code: 0
However, when I try to compile essentially the same code in Julia (with
Cxx), I see the following ERROR:
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 exceptiontest()
{
try
{
divide(1, 0);
}
catch(int i)
{
if(i==ZeroDivisionError)
{
std::cerr<<"Divide by zero error";
}
}
}
In file included from :1:
:9:25: error: cannot use 'throw' with exceptions disabled
throw ZeroDivisionError;
^
:16:20: error: cannot use 'try' with exceptions disabled
try
^
Does anyone know how I can switch on exception handling in Clang for
building Julia?
Alternatively, if the exception flag is already included by default, then
at least I know to focus on why it is not being used by Cxx.
Thank you for your time.
Max