Link to home
Start Free TrialLog in
Avatar of manx
manx

asked on

Error handler in VC ++

Hi,
   Is there such a thing in VC++ like the VB "On Error GoTo NormalErr" error handling facilities?

If so how do I go abt implementing it ?

Regards

ManX
ASKER CERTIFIED SOLUTION
Avatar of vachooho
vachooho
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of manx
manx

ASKER

Just a little clarification abt the thing,


How abt something like

main
{
  try
  {
   dosomething();
   c++ code
   domorethings();
  }

  catch (exception)
  {
   exception handler
  }
...

Will this catch all exceptions that arise within sub functions called within the c++ code i.e exceptions that arise in the dosomething and domorethings functions

Also is it possible to have a sub level exception handler within the sub functions themselves, i.e if the sub function has an exception handler, it will be used, if not it goes back up to the calling functions exception error handler and so on

Thanks for the prompt reply

Regards

ManX


Also is it possible to have a sub level exception handler within the sub functions themselves, i.e if the sub function has an exception handler, it will be used, if not it goes back up to the calling functions exception error handler and so on

Sure it is right

all following costructions correct

void Sub1()
{
try
{
....
}
catch(...)
{

}
}

void Sub2()
{
....
}

int main(..)
{
try
{
    Sub1();
    Sub2();
}
catch(...)
{
}
}

Sub2() does not have exception handler - thus on error exception will be caught in main.
Exceptions in Sub1() will be caught in Sub1 body because it has try-catch block.




nested  try-catch blocks

try
{
   DoSomething();
   try
   {
     DoOtherthing();
   }
   catch(...)
   { ... }
   DoBetterhing();
}
catch(...)
{
}

DoBetterthing() will be always called if DoOtherthing() is called.


and of course your sample
{
  try
  {
1   dosomething();
2   c++ code
3   domorethings();
  }

  catch (exception)
  {
   exception handler
  }

no matter where exceptions arised - in line 1, 2 or 3 - catch block will work.

if called funcions have their own try-catch blocks - nearest catch will work.

hope this helps
Avatar of manx

ASKER

Comment accepted as answer
Avatar of manx

ASKER

Thanks vachooho