T
Tad Marshall
Hi,
I'm having limited luck getting an ApplicationException to work right in my
code. This is VB.NET, VS 2003, Windows XP SP2, .NET Framework 1.1.
I thought it would be convenient to take advantage of exception handling to
deal with the case of the user clicking the Cancel button while a long
operation was running. So, I declared a class inherited from
ApplicationException and I Throw one of these with the text "User pressed
Cancel" in the OnClick handler for the Cancel button. I have a
Try/Catch/Finally/End Try block around the code that is running, and it all
works great. I catch the exception, log a message that the user pressed
cancel, then run the Finally block and close all my files, and I return to
the OnClick handler for the Start button that began the operation, and it
re-enables the Start button and returns from the OnClick handler.
Then my program exits, with error code 0.
If I take out the Try stuff, VS 2003 catches it and puts up a dialog saying
that a UserInterruptException has occured with additional information "User
pressed Cancel". I can Break into the debugger and look around, but if I
Continue then it is the same as when I had the Try block ... everything
gracefully cleans up just as designed, and then the program exits, which is
NOT my design.
Am I missing something? I've used Structured Exception Handling in Win32,
and all I had to do was handle the error and my code would keep running. I
thought that was the whole point! You can exit if you want to, but if you
can handle the error and continue, then you do that instead.
Any suggestions? Thanks!
Tad
I'm having limited luck getting an ApplicationException to work right in my
code. This is VB.NET, VS 2003, Windows XP SP2, .NET Framework 1.1.
I thought it would be convenient to take advantage of exception handling to
deal with the case of the user clicking the Cancel button while a long
operation was running. So, I declared a class inherited from
ApplicationException and I Throw one of these with the text "User pressed
Cancel" in the OnClick handler for the Cancel button. I have a
Try/Catch/Finally/End Try block around the code that is running, and it all
works great. I catch the exception, log a message that the user pressed
cancel, then run the Finally block and close all my files, and I return to
the OnClick handler for the Start button that began the operation, and it
re-enables the Start button and returns from the OnClick handler.
Then my program exits, with error code 0.
If I take out the Try stuff, VS 2003 catches it and puts up a dialog saying
that a UserInterruptException has occured with additional information "User
pressed Cancel". I can Break into the debugger and look around, but if I
Continue then it is the same as when I had the Try block ... everything
gracefully cleans up just as designed, and then the program exits, which is
NOT my design.
Am I missing something? I've used Structured Exception Handling in Win32,
and all I had to do was handle the error and my code would keep running. I
thought that was the whole point! You can exit if you want to, but if you
can handle the error and continue, then you do that instead.
Any suggestions? Thanks!
Tad