Can We Have User Defined Exceptions ( Leaves - Error ) in Symbian C++ ?
| Mon, 2006-05-15 06:21 | |
|
Hello EveryOne,
I am looking for user defined leaves in Symbian C++. As far as I know, exception handling mechanism is implemented using 'Leave - Trap' in Symbian. For leaving from a function it has to call User::Leave( ). And for catching, TRAP( error, function which leaves ){ } Now my question is, is there any mechanism like user defined exception in Symbian ? or in other words can we set the 'error' variable in TRAP( ) to a perticular value before calling User::Leave( ) ? Or please suggest me if there is any other alternative to implement user defined exception in Symbian C++. Thank You Sanket Meghani. |
|






Forum posts: 104
If i understand correctly what you want to do the idea is that you want to be able to TRAP your user defined leave code.
If that is the case then you simply call the User::Leave as you have said but call it with a number that you have defined (preferably an enum to minimize confusion). You then TRAP it in the conventionaly way and do an if(err == EMyErr) to check if it was your error or a system leave that caused the leave.
HEALTH WARNING: make sure the value of the leave code that you pass back doesn´t conflict with any of the system ones. For a heads up on what the system defines check out:
http://www.newlc.com/Symbian-OS-Error-Codes.html
Cheers
PL
Forum posts: 4
Thank You for the reply.
Sanket Meghani.
Forum posts: 8
Implementation is given below:
Caller()
{
CConsole gConsole = CConsole::NewL();
TInt error;
TRAP(error,UserDefined());
if(error)
{
  gConsole->Printf(_L("error thrown"));
}
}
UserDefined()
{
 User::Leave(EMyErr);
}
It Crashes at USer::Leave(EMyErr)
Please tell me the reason.
Thanks in advance.
Forum posts: 194
static CTrapCleanup* TrapCleanup = CTrapCleanup::New();
Forum posts: 8
Oh...Got it !!!
for WINS build it crashes
but works fine with ARMI build.
Moral of the story:
"Don't rely on Emulators"
Thanks .
Forum posts: 194
You should find out why/where it crashes.
Forum posts: 8
I realise that.
If I want to TRAP a method which returns TBool, how can I get returned value in calling method.
TBool CMyClass::CallSubM(_indx, jij, _ete, ..., vtaltn )
{
}
Calling()
{
//This is not correct.
result=TRAPD(errorCallSubM,CallSubM(_indx, jij, _ete, ..., vtaltn ));
}
Thanks in advance.
Forum posts: 194
TRAPD(ret, result = CallSubM(...))
Forum posts: 8
It works......
Thanks a lot.