How to catch unhanded exception ?
-
I've got QCoreApplication. I run it at Microsoft Windows OS and need to catch unhanded exception. I try to do this:
@try{
m_defMail.setDefault();
#ifdef _DEBUG
m_defMail.setDebugDefault();
#endif// int g = 0;
// int t = g/g;initPathes();
initArgs();
analyseArguments(argc, argv);
sendAllMessages();
}
catch (...){
qDebug() << "sxMailSender: Unhanded Exception!!! Application will be terminated.";
}--@
but it's have no effect.Edit: moved to C++, as it is no Qt related topic. Gerolf
-
which exception do you try to catch?
There are two types:- "normal" exception (by throw) which can be caught by try/catch
- structured exceptions (like div 0, null pointer, etc.) which can't be catched by try/catch. For those you need try/except which is not possible in functions using C++ objects :-( Then you need an exception translator (_set_se_translator). There you can convert the structured exception into a C++ exception and throw that one. But sorry,. I can't give you code for that, as it is closed source what I do here.
-
@try{
m_defMail.setDefault();
#ifdef _DEBUG
m_defMail.setDebugDefault();
#endifint g = 0;
int t = g/g;initPathes();
initArgs();
analyseArguments(argc, argv);
sendAllMessages();
}
catch (...){
qDebug() << "sxMailSender: Unhanded Exception!!! Application will be terminated.";
}--@I mean for example in this source i try to catch div by zero. But I can't reach catch section and get OS exception message. So I need some how to catch all OS exceptions for my application.
-
Also you can use flag /EHa if you use compiler from Microsoft (description this flag you can find in "MSDN":http://msdn.microsoft.com/en-us/library/1deeycx5(v=vs.80).aspx
-
I use the Windows ::SetUnhandledExceptionFilter API:
@
....
::SetUnhandledExceptionFilter( IGExceptionHandler );
...#if defined(WIN32)
LONG WINAPI IGExceptionHandler( struct _EXCEPTION_POINTERS pExceptionInfo )
{
DWORD code = pExceptionInfo->ExceptionRecord->ExceptionCode;
IGLog( qDebug(), "Handling Visimeet Exception : " << code << " Address: " << pExceptionInfo->ExceptionRecord->ExceptionAddress);
if ( code == STATUS_ACCESS_VIOLATION )
{ // add this bit o' info
IGLog( qDebug(), "*** ACCESS VIOLATION ")
}
else if ( code == STATUS_ILLEGAL_INSTRUCTION )
{
IGLog( qDebug(), " ILLEGAL INSTRUCTION ");
}
else if ( code == STATUS_FLOAT_DIVIDE_BY_ZERO || code == STATUS_INTEGER_DIVIDE_BY_ZERO )
{
IGLog( qDebug(), " DIVIDE BY ZERO ");
}
else if ( code == IGLOGGER_FATAL_ERROR )
{ // our interanl error if qFatal is used
IGLog( qDebug(), " Qt FATAL ERROR ")
}
else
{
IGLog( qDebug(), " Unknown Fatal Error ****");
}LONG retval = EXCEPTION_EXECUTE_HANDLER; visiqt->sendReport(true); return retval;
}
@