Re: exception handling on Unix

Posted by Xavier.Abulker on
URL: http://quantlib.414.s1.nabble.com/exception-handling-on-Unix-tp2545p2552.html

Hi Luigi,

I'm using the EuropeanOption.cpp example to deduce the implied volatility
of options.
There's the try-catch in the source code as you explained me.
Now everything goes fine except when it is impossible to find a solution.
the Brent algorithm should give me an exception like:"Exception happend for
matrix point: root not bracketed: f[0.0001000000,4.0000000000] ->
[0.63761133978130147000,6.27375654274655490000]" (I see that on NT) but on
Unix I only see  a core dump.

I'm wondering if it's not a bug with gcc with the option -O2 or -O3, I
found on internet that people reported the same problem with gcc (until
3.1) on Unix or Linux using this option to compile.


Xavier



                                                                                                                       
                    Luigi Ballabio                                                                                    
                    <luigi.ballabio@fast       To:     [hidden email], [hidden email]  
                    webnet.it>                 cc:                                                                    
                                               Subject:     Re: [Quantlib-users] exception handling on Unix            
                    21/05/2003 10:34                                                                                  
                                                                                                                       
                                                                                                                       




At 09:45 AM 5/21/03 +0200, [hidden email] wrote:
>Excuse me if this question is too basic but I'm trying to understand how
to
>handle Quantlib exceptions on Unix.
>I haven't changed any option to compile quantlib with gcc and when an
>exception is returned I have "core dump" instead of a beautiful error
>message.

Xavier,
         I'm not sure I understand. What is it exactly that you're doing?
Are you linking the library to some application? And does the application
properly handle exceptions? I mean, if you just write:

int main() {
         throw Error("Boo!");
         return 0;
}

the program will just abort---you'll have to write:

int main() {
         try {
                 throw Error("Boo!");
                 return 0;
         } catch (std::exception& e) {
                 std::cerr << e.what() << std::endl;
                 return 1;
         } catch (...) {
                 std::cerr << "unknown error" << std::endl;
                 return 2;
         }
}

after which the program will tell you what was the exception. Also, I'm not

sure that even the above will work if some special kind of errors are
raised (such as division by zero). In that case, you'll have to find out
when that happens and add a check before the division...

Was this what you were asking, or am I off the mark?

Later,
         Luigi






*************************************************************************
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration.
La Fimat et ses filiales declinent toute responsabilite au
titre de ce message s'il a ete altere, deforme ou falsifie.
                    ********
This message and any attachments (the "message") are confidential and
intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
E-mails are susceptible to alteration.
Neither Fimat nor any of its subsidiaries or affiliates shall
be liable for the message if altered, changed or falsified.
*************************************************************************