Undestanding Exception Processing

G

gemel

I am fairly comfortable with much of the .NET Exception mechanism, but
I'm a bit unsure of some areas.

1. When an exception occurs and the exception is not caught then
Exception processing will continue at the next Catch block up the
stack. When this happens will the 'Finally' block of the original
'Try/Catch' be executed?

2. If I wish to recover from the error that caused the Exception can I
put the Try/Catch in a loop so that I can retry the statement that
caused the error?

3. Can I mix Exception handling with the traditional On Error Resume
statements to allow me to do graceful recovery?


Regards

John L
 
M

Maqsood Ahmed

Answer 1: Following is the flow trace when an exception hasn't been
serviced in its original try/catch block and continue at the next catch
block.

i. Finally of original try/catch
(Optional) Finally of other try/catch blocks (up the stack) where
exception was not serviced
ii. Catch block where exception was serviced.
iii. Finally of the catch where exception was serviced.

Answer 2: Try/catch can not be looped unless you use labels (see: goto
statement). I personally think that it is not a good idea to loop a
try/catch. because if a statement fails once, it'll always fail to pass
try/catch.

I don't have much Idea about your third question.
HTH. Cheers :)

Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
G

gemel

Thank you very much for responding to my post. With regard to the
looping of the try, this is what I need to do:

Say I am validating input from a textbox and I use a try block to help
me. If an Exception occurs then I would like to allow a retry of the
input again. How can I go back retry the code that has just 'failed'


Regards

John L
 
M

Maqsood Ahmed

Hello,
I prefer to write another method for validing any data. Show a pop up
message when an exception occurs and return from the validation method.
Use bool to show success or failure of the validation.
Using this architecture you can always call this method to call the
try/catch again and again on retries for validation of the input text.

HTH. Cheers.

Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 

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