Can We Have User Defined Exceptions ( Leaves - Error ) in Symbian C++ ?

Login to reply to this topic.
Mon, 2006-05-15 06:21
Joined: 2006-05-12
Forum posts: 4
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.

Mon, 2006-05-15 10:37
Joined: 2006-04-05
Forum posts: 104
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
Hi,

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
Mon, 2006-05-15 12:00
Joined: 2006-05-12
Forum posts: 4
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
Ya, I got it now.

Thank You for the reply.

Sanket Meghani.
Wed, 2006-08-02 18:49
Joined: 2006-07-27
Forum posts: 8
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
I have tried this but programm crashes even though i have TRAPed it.

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.

Wed, 2006-08-02 19:27
Joined: 2006-03-04
Forum posts: 194
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
Your using CConsole hence this presumbably can't be a UI application hence that means you probably haven't installed a trap harness


static CTrapCleanup* TrapCleanup = CTrapCleanup::New();
Wed, 2006-08-02 19:28
Joined: 2006-07-27
Forum posts: 8
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy

Oh...Got it !!!

for WINS build it crashes
but works fine with ARMI build.

Moral of the story:
"Don't rely on Emulators"

Thanks .
Wed, 2006-08-02 20:28
Joined: 2006-03-04
Forum posts: 194
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
If there's a mismatch in behaviour its usually the other way round - stuff runs on the emulator and not on hardware. The emulator is your friend, don't think of it as being unreliable.

You should find out why/where it crashes.
Fri, 2006-08-04 05:27
Joined: 2006-07-27
Forum posts: 8
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
Ok...
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.


Fri, 2006-08-04 17:20
Joined: 2006-03-04
Forum posts: 194
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy
TBool result;
TRAPD(ret, result = CallSubM(...))
Fri, 2006-08-04 17:44
Joined: 2006-07-27
Forum posts: 8
Re: Can We Have User Defined Exceptions ( Leaves - Error ) in Sy

It works......
Thanks a lot.
  • Login to reply to this topic.