Exception Handling In Symbian C++
| Fri, 2006-05-19 06:21 | |
|
|
Hi Developers, i know exception handling in Desktop C++... e.g. try { : ://some code causing error...such as Zero divide... : } catch(...) { cout<<"\n Exception occured !!"; } i've read that in symbian C++ we do the same using..... TRAPD(err,TestErrorL()); if(err) { User::InfoPrint(_L("Exception Occured.")); } my problem is that..as soon as i reach the exception causing statement inside TestErrorL() method....my program crashes. so...i would like to know how to trap exceptions in Symbian C++. i want to trap any kind of exception as catch(...) does in C++. please throw some light on it... Cheers!! CodePupil Thanks and Regards |






Forum posts: 148
Forum posts: 105
but in C++...it is not required to use throw every time...
if..any exception occures inside try block...it will be catched by catch(...)
you can check it for yourself as well.
and also where to use..User::Leave()..because program crashes as soon as it reaches that particular statement...which causes the exception...
Can't we trap the Zero divide Exception in Symbian C++ as Normal C++ does ??
Cheers!!!!!
CodePupil
Thanks and Regards
CodePupil
__________________________
You are I and I am he .. !!
You can, and you can catch divide by 0 exceptions, its possible to install an exception handler.
Forum posts: 92
Forum posts: 105
hey...Guest...
please tell me how can it be done ??
any way.. i tell you the real problem...
my program crashes on real device giving panic : KERN-EXEC 3
and some times : KERN-EXEC 0
but it doesn't happen always.
most of the time it runs quiet well.....
so please tell me how can i trap those ....
and my previous question was regarding C++'s try/catch Vs Symbian's TRAP...
in C++... try block automatically throws exception like Zero divide..which can be caught by catch(...).
how can this same handle in Symbian
although i dont know too much about symbian's error handling...yet hitherto i've come to this point that C++'s try/catch mechanism is far better than Symbian's......
Cheers!!
CodePupil
Thanks and Regards
CodePupil
__________________________
You are I and I am he .. !!
Forum posts: 9
Hi CodePupil,
maybe you know Windows structured exception handling.
It is nearly the same here.
Use SetExceptionHandler with KExceptionInteger and
handle EExcIntegerDivideByZero in your ExceptionHandler()
Forum posts: 105
can you please provide me some example code/URL having some example regarding this...if you dont mind??
Cheers!!
CodePupil
Thanks and Regards
CodePupil
__________________________
You are I and I am he .. !!
Forum posts: 9
void PupilsExcHandler(TExcType aExc)
{
if(aExc == EExcIntegerDivideByZero)
{
return; // ignore
//User::Leave(KErrDivideByZero);
}
else
{
_LIT(KPanicCategory,"Exception");
User::Panic(KPanicCategory, TExcType(aExc));
}
}
As soon as possible in your current thread:
#ifdef EKA2
User::SetExceptionHandler(PupilsExcHandler, KExceptionInteger);
#else
RThread().SetExceptionHandler(PupilsExcHandler, KExceptionInteger);
#endif
Forum posts: 8
Any idea what's going on?
Forum posts: 723
It's worth noting that in case you want to catch each and every panic in your (single threaded) program, then you might want to run your code from within a separate thread so that when that thread exits for some reason (panics, for example) your main thread takes the control back and can evaluate the reason of exiting.
Cheers,
Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 8
User::SetExceptionHandler(handler, KExceptionFault|KExceptionInteger|KExceptionAbort|KExceptionKill|KExceptionFpe|KExceptionUserInterrupt);
My problem is that whenever a KERN-EXEC 3 happens, it is caught by the "handler" function, but only when running on the emulator. If I run the very same code on a mobile phone, specifically the N93, the "handler" function is never called; on the emulator I would never see the KERN-EXEC 3 message, but on the phone I would see it.
Forum posts: 723
Also note that it's the last resort for the kernel to call a user-defined exception handler. Based on what you wrote it seems that the kernel has already shown the dialog by the time it calls your function.
Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 8
Forum posts: 723
The advantage of the thread solution is that it won't make your program collapse. So basically although the dialog is still shown your program continues to execute. That's sometimes very valuable, but I admit that it doesn't entirely solve your problem.
Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/