E
Emil Astrom
Hi!
I wonder if there's a way to retrieve information about thrown, not yet
handled exceptions. My situation is similar to the code below:
class MySession : IDisposable
{
:
:
Dispose()
{
if (mytransaction.IsOpen)
throw new SessionException("Transaction not closed!", XXX);
}
}
OtherFunc()
{
using (MySession session)
{
:
throw new ErrorException("whoops!");
session.Commit();
}
}
What I want to do is to have a Dispose() method that can include the already
thrown exception as an inner exception in its own exception that it needs to
throw if it's called prematurely. What I would like to have in the example
above is a thrown SessionException with the ErrorException instance in the
InnerException property. Can this be done?
If not, then I can only see two options:
* not include ErrorException in my SessionException when I throw it, but
that means losing the original error
* not throw an exception in my Dispose method at all, but that means not
having any error messages for improper use of the MySession class, e.g.
forgetting to call Commit().
Maybe someone have more (and better) alternatives? All suggestions are
greatly appreciated!
Regards,
Emil
I wonder if there's a way to retrieve information about thrown, not yet
handled exceptions. My situation is similar to the code below:
class MySession : IDisposable
{
:
:
Dispose()
{
if (mytransaction.IsOpen)
throw new SessionException("Transaction not closed!", XXX);
}
}
OtherFunc()
{
using (MySession session)
{
:
throw new ErrorException("whoops!");
session.Commit();
}
}
What I want to do is to have a Dispose() method that can include the already
thrown exception as an inner exception in its own exception that it needs to
throw if it's called prematurely. What I would like to have in the example
above is a thrown SessionException with the ErrorException instance in the
InnerException property. Can this be done?
If not, then I can only see two options:
* not include ErrorException in my SessionException when I throw it, but
that means losing the original error
* not throw an exception in my Dispose method at all, but that means not
having any error messages for improper use of the MySession class, e.g.
forgetting to call Commit().
Maybe someone have more (and better) alternatives? All suggestions are
greatly appreciated!
Regards,
Emil