Throw Exception and using Dispose?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TVIgRQ==?=

    #1

    Throw Exception and using Dispose?

    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_Err or() 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

  • Scott M.

    #2
    Re: Throw Exception and using Dispose?

    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?


    "MR E" <MR E@discussions.m icrosoft.comwrote in message
    news:75CDFE72-F8D3-47EA-AC75-E766062296E0@mi crosoft.com...
    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_Err or() 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
    >

    Comment

    Working...