[Qt-interest] qt and exception handling
BRM
bm_witness at yahoo.com
Tue Aug 2 17:32:27 CEST 2011
>________________________________
>From: Benjamin <bebl at mageta.org>
>To: qt-interest at qt.nokia.com
>Sent: Monday, August 1, 2011 3:22 PM
>Subject: [Qt-interest] qt and exception handling
>
>Hej folks,
>
>I got a little problem with finding the right exception-handling-policy,
>maybe you can help me.
>I developed a litte tool which is used by both, windows- and
>linux-users. Within the code I have some "dead-end-states", which are
>states that I can think of, but can not think of a "good" solution to
>handle them (mostly triggered by improper use of function, e.g.
>"switch(foo) { ...; default: oops(); }").
>Till now I solved this by throwing a exception and not catch it later.
>This will crash the program and linux will print a short message to
>stderr, where the crash occurred and what the reason was (the given
>exception-parameters). Windows prints nothing, but shows a
>failure-message (I don't know if there is any way to get the
>reason/place of the crash under windows).
>
>So.. one of the users of the tool reported yesterday (after weeks with
>nothing but praise ;) ) that it crashed with some strange
>failure-message (windows). I can't track this down, because I have
>nothing to work with, since windows doesn't show any useful information.
>That's the reason why I would like to implement a policy which at least
>writes the exception (place and reason) into a log-file or something
>like this (maybe even a core-dump.. that would be heavenlies :D).
>
>Provides qt a way to do so or knows someone of you a good way to handle
>this? The exceptions can occur in multiple threads.
>
What version of Windows was he using?
Window XP and earlier usually gave that information but you would have to click on something in the dialog to get to it.
Windows 2008 (at least, probably 2003 as well - and likely Vista) and Windows 7 make it very hard to get that information using the default configuration of Windows; where you have to instead modify the Windows Registry to enable the minidumps, dumps, etc that were generated by default under WinXP and earlier.
That said, what I would suggest doing is using the qDebug()/qCritical()/qFatal() interfaces wherever you need to log that kind of information.
Then, simply install a filter to catch that information, record it to the log (of your choice), and toss the exception after you have already logged it using those interfaces.
Probably something like:
switch(...)
{
...
default:
{
const char* message = "some error message";
qDebug("%s", message);
throw myExceptions(message); // or however you throw it now
}
break;
};
While I don't use exceptions, I do use that method to pull in log data from sources that cannot use my log signal but can use those interfaces - e.g. static functions, non-object functions, etc.
Works great.
$0.02
Ben
More information about the Qt-interest-old
mailing list