Question on Exceptions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I have a question regarding exceptions

When I have a try/catch block and within the try block I have an exception, it then goes to the catch block to deal with the error. thats all fine, but once I figured out what the problem is and fixed it in the catch block, how do I get my code to run FROM the same line that raised the exception i.e. try again. And what do I do If I can't resolve the error, what do I need to do in my catch block to tell the code NOT to run from the line that raised the exception, but instead jst exit the function and notify the user

Thanks for any hel

Kevin
 
Hi Kevin,

while(some condition)
{
try
{
//stuff
break;
}
catch(SomeKindOfException ex)
{
// try to fix

if(unable to fix)
throw new SomeKindOrOtherException("Could not fix it!", ex);
}
}

This will let you continously try until you give up by throwing a new
exception with the message "Could not fix it!". The original exception is
stored as an InnerException


Happy coding!
Morten Wennevik [C# MVP]
 
Back
Top