Error Recovery Using Exceptions

G

gemel

I wish to implement error recovery using the Exception mechanism
However, I'm not sure I fully appreciate some of the detail in which
this works.

The code that contains a potential error is included in the Try block.
The Catch block is used to catch this exception. The Finally block
will then execute after the Exception has been handled. My questions
are:

1. If the Exception is caught in the Catch block is this referred to
as 'swallowing the exception'

2.If the Exception that is raised is not caught in the Catch block
then will the code in the Finally block still be executed before the
Exception processing transfers to the next higher Catch block.

3. If the Exception is successfully caught in the Catch block will it
be possible to try to recover from the error and do the Try block
again. That is, can I put the Try/Catch block in a loop and then use
my code to determine when to exit from the loop.

Regards

John L
 
A

Alvin Bruney [MVP - ASP.NET]

1. If the Exception is caught in the Catch block is this referred to
as 'swallowing the exception'
No, swallowing is just that - swallowing and pretend it wasn't there
for instance
try
{
bogus code
}
catch
{
}
//contine with code here
2.If the Exception that is raised is not caught in the Catch block
then will the code in the Finally block still be executed before the
Exception processing transfers to the next higher Catch block.
Finally blocks are guaranteed to execute. Take that with a grain of salt.
There are instances when the finally blocks don't fire. For most
circumstances, they do.

3. If the Exception is successfully caught in the Catch block will it
be possible to try to recover from the error and do the Try block
again. That is, can I put the Try/Catch block in a loop and then use
my code to determine when to exit from the loop.
sure. i do that with regularity.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top