On Monday, December 1, 2014 9:18:41 AM UTC+10, Keno Fischer wrote:
>
> This is primarily a Cxx.jl issue, though you might run into problem if 
> you're trying to unwind through non-C++ frames later.
>

To amplify, Julia uses lots of libraries that are not guaranteed to be 
exception safe, and can leak resources or leave memory in unknown and/or 
illegal states when you throw exceptions through them.  If your exceptions 
are only used to terminate the process thats mostly fine since most 
resources (memory, open files) are returned on process terminate anyway and 
the state of memory doesn't matter.  But if you catch the exceptions after 
they have unwound through non-c++ code and then you try to continue, you 
could run into problems with leaks or data structures in indeterminate 
states. Caveat Emptor :)

Cheers
Lex

 

> In any case, in the spirit of experimentation, you can enable exception 
> handling by setting the appropriate options from here:
>     
> https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/LangOptions.def#L106-L109
>
> in bootstrap.cpp, e.g. here:
>     https://github.com/Keno/Cxx.jl/blob/master/src/bootstrap.cpp#L464
>
> On Sun, Nov 30, 2014 at 5:59 PM, Max Suster <[email protected] 
> <javascript:>> wrote:
>
>> 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
>>
>
>

Reply via email to