Throw Exception and using Dispose?

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

Guest

This may seem like a stupid question but in C#:

Say for instance I have a set of SQL processes that I run via
ExecuteReader(). These processes return several pieces of information to the
DataReader, including any SQL exception that occurred (This may include
messages I generated b/c something didn’t check out based on programmed
requirements, but its not a runtime exception as far as SQL or C# is
concerned).

I then check this exception (or programmed error message) and perform a TROW
NEW EXCEPTION() with a more friendlier message and perform some other tasks.
I realize throw exception is costly and only do it when you have to, but its
a great way to quickly access the Application_Error() in global asx for
logging errors and generating notifications to the programmer. The problem is
I still need to go back and dispose of the class objects that where created
before the exception is thrown. If I try to dispose of the class first then I
get an Exception of the Exception. How can manually throw exceptions and
still go back to cleanup my code when Im not using a TRY/FINALLY b/c again
these are exception I threw, not the CLR?
Of course any code I place after throw new exception() gives me an
unreachable code detected during compile.

I know Im missing something really simple here
 
Why can't you instantiate your new exception and configure it with any
information you want, then dispose what you need to and then throw your
exception?
 
Back
Top