Hi everyone,
This is my first experience with QuantLib (C++). I am working with version 0.9.7. Since i don't have a very good background on pricing financial instruments it's quite difficult to me to understand some error messages as well as figure out what caused it. Do you think, I mean code mantainers, it is possible to add some kind of exception stack trace to all quantlib application exceptions? I was thinking in something like: http://www.eyt.ca/blog/item/108/ please let me know if this could be a good improvement or if it is a bad idea! I would be glad to work in this improvement if you all think it could be a nice feature! Regards, Eduardo. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Mon, 2008-12-01 at 11:14 +0100, Eduardo Montoya wrote:
> [...] it's quite difficult to me to understand some error messages as > well as figure out what caused it. Do you think, I mean code > mantainers, it is possible to add some kind of exception stack trace > to all quantlib application exceptions? > > I was thinking in something like: > > http://www.eyt.ca/blog/item/108/ > > please let me know if this could be a good improvement or if it is a > bad idea! I would be glad to work in this improvement if you all think > it could be a nice feature! Hi Eduardo, file and line information can already be added to the error messages. If you're on Linux or Mac OS X, run ./configure --enable-error-lines and rebuild; if you're on Windows, edit ql/userconfig.hpp and uncomment line 41 (the one that #defines QL_ERROR_LINES.) Stack trace information would be nice, too. If you want to submit a patch that does it, you're welcome. Later, Luigi -- All generalizations are dangerous, even this one. -- Alexandre Dumas ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hello, --enable-error-lines worked very well for me.
I didn't know that in C++, checked exceptions clears the stack. It seems there is not a portable solution that allows to add some stack tracing capabilities to C++ programs. I found a very interesting project at http://www.nongnu.org/libunwind/index.html that claims to: "...define a portable and efficient C programming interface (API) to determine the call-chain of a program. The API additionally provides the means to manipulate the preserved (callee-saved) state of each call-frame and to resume execution at any point in the call-chain (non-local goto). The API supports both local (same-process) and remote (across-process) operation. As such, the API is useful in a number of applications. ..." I will try to play a little with this in order to see if it can be a useful feature. In the meantime, since I am working in a linux CentOS environment, I decided to compile my programs with debug information and decided to use the GNU debugger in order to examine the backstack. the attached c++ source, with the try{} catch{} block, gives me the following output when executed from command line. $ ./ZeroCouponBondImpliedCurve defining bond from November 26th, 2008 to May 30th, 2009 linking bond to price engine... price engine linked. checked exception has been thrown because termstructure.cpp:80: In function `void QuantLib::TermStructure::checkRange(QuantLib::Time, bool) const': negative time (-0.0657534) given $ if I run it with the GNU debugger, it obviously gives me an empty stack. $ gdb ZeroCouponBondImpliedCurve (gdb) run Starting program: /home/devel/quantlibtest/Bonds/ZeroCouponBondImpliedCurve [Thread debugging using libthread_db enabled] [New Thread -1208703280 (LWP 5163)] defining bond from November 26th, 2008 to May 30th, 2009 linking bond to price engine... price engine linked. checked exception has been thrown because termstructure.cpp:80: In function `void QuantLib::TermStructure::checkRange(QuantLib::Time, bool) const': negative time (-0.0657534) given Program exited with code 01. (gdb) bt No stack. (gdb) if try{} catch{} block is eliminated, the I have a stack. (gdb) bt #0 0x008017f2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 #1 0x0024aba0 in raise () from /lib/libc.so.6 #2 0x0024c4b1 in abort () from /lib/libc.so.6 #3 0x006c1540 in __gnu_cxx::__verbose_terminate_handler () from /usr/lib/libstdc++.so.6 #4 0x006bf025 in std::set_unexpected () from /usr/lib/libstdc++.so.6 #5 0x006bf062 in std::terminate () from /usr/lib/libstdc++.so.6 #6 0x006bf11b in __cxa_rethrow () from /usr/lib/libstdc++.so.6 #7 0x08094482 in QuantLib::LazyObject::calculate (this=0xbfaaebf0) at /usr/local/include/ql/patterns/lazyobject.hpp:143 #8 0x080944e4 in QuantLib::Instrument::calculate (this=0xbfaaebf0) at /usr/local/include/ql/instrument.hpp:143 #9 0x0118ada8 in QuantLib::Bond::settlementValue (this=0xbfaaebf0) at bond.cpp:275 #10 0x0118b338 in QuantLib::Bond::dirtyPrice (this=0xbfaaebf0) at bond.cpp:271 #11 0x0118b3b8 in QuantLib::Bond::cleanPrice (this=0xbfaaebf0) at bond.cpp:267 #12 0x0806e58e in main () at ZeroCouponBondImpliedCurve.cpp:312 (gdb) after this, I could figure out the call chain: QuantLib::Bond::cleanPrice calls QuantLib::Bond::dirtyPrice QuantLib::Bond::dirtyPrice calls QuantLib::Bond::settlementValue QuantLib::Bond::settlementValue calls QuantLib::Instrument::calculate QuantLib::Instrument::calculate calls QuantLib::LazyObject::calculate but when I read file include/ql/patterns/lazyobject.hpp:143 Oops, I could see that there is a checked exception that doesn't allow the debugger to be aware of the previous calls that originated the exception. include/ql/patterns/lazyobject.hpp:143 ... 135 inline void LazyObject::calculate() const { 136 if (!calculated_ && !frozen_) { 137 calculated_ = true; // prevent infinite recursion in 138 // case of bootstrapping 139 try { 140 performCalculations(); 141 } catch (...) { 142 calculated_ = false; 143 throw; 144 } 145 } 146 } ... I can see that exception has been raised when calling virtual method performCalculations() the problem here, FOR STACK TRACING PURPOSES ONLY, is the try {} catch{} block that doesn't allow the original exception to be propagated until the main caller. Reading Luigi's (Ballabio) book, Implementing QuantLib, chapter 2, pages 8 and 9 I could understand the reason: "... care must be taken to restore it [_calculated flag] to false if an exception is thrown ..." My questions is: It could be possible to figure out another mechanism to achieve the same functional requirements without trapping exceptions in library code, leaving the choice of trapping exceptions to the final API user? In that way it would be possible to keep the stack so we can have more informations on why exception happens! thanks in advance for your answers. Regards, Eduardo > Subject: Re: [Quantlib-users] C++ exception Stack Trace after raising quantlib application exceptions. > From: [hidden email] > To: [hidden email] > CC: [hidden email] > Date: Mon, 1 Dec 2008 12:27:09 +0100 > > On Mon, 2008-12-01 at 11:14 +0100, Eduardo Montoya wrote: > > [...] it's quite difficult to me to understand some error messages as > > well as figure out what caused it. Do you think, I mean code > > mantainers, it is possible to add some kind of exception stack trace > > to all quantlib application exceptions? > > > > I was thinking in something like: > > > > http://www.eyt.ca/blog/item/108/ > > > > please let me know if this could be a good improvement or if it is a > > bad idea! I would be glad to work in this improvement if you all think > > it could be a nice feature! > > Hi Eduardo, > file and line information can already be added to the error messages. > If you're on Linux or Mac OS X, run > > ./configure --enable-error-lines > > and rebuild; if you're on Windows, edit ql/userconfig.hpp and uncomment > line 41 (the one that #defines QL_ERROR_LINES.) > > Stack trace information would be nice, too. If you want to submit a > patch that does it, you're welcome. > > Later, > Luigi > > > -- > > All generalizations are dangerous, even this one. > -- Alexandre Dumas > > > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Eduardo, Eduardo Montoya <[hidden email]> writes: > Hello, --enable-error-lines worked very well for me. > > I didn't know that in C++, checked exceptions clears the stack. It > seems there is not a portable solution that allows to add some stack > tracing capabilities to C++ programs. Exceptions in C++ are not designed to supposed debugging of programs, but rather recovery of programs from external factors and/or misuse (and maybe bugs) in a production environment. If you can run under the debugger, I would recommend you set a break-point on the constructor of the base class of the exception hierarchy and then you will have the back-trace available every time an exception is created. Hope that helps, Bojan -- Bojan Nikolic || http://www.bnikolic.co.uk ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |