C
clintonb
When using the Enterprise Library Excption Handling Application block,
how can I pass extra contextual information to the Exception Handling
block so I can make more user-friendly exceptions.
Here is an example where I'd like to add contextual info. I have a 3rd
party report engine that throws exceptions. I'd like to wrap that
exception in a more user-friendly exception. If I open a report file
that I assume exists, and it doesn't exist, the ReportEngine will throw
an exception. But the message is too generic and not the most
user-friendly. I'd like to wrap it in some new exception that would
have some message that says: "Unable to open report file
'SomeReport.rpt'".
The problem is, to use the exception handling block, you call
ExceptionPolicy.HandleException(), but the only parameters are the
exception and the policy name. It seems like the message of the
wrapping exception is "hard coded" in the configuration file.
Have any of you users of the Exception Handling Application Block tried
to do something similar to what I want? If so, how did you handle it.
Thanks.
try
{
ReportEngine engine;
engine.OpenReport("SomeReport.rpt");
}
catch( ReportEngine.FileNotFoundException ex )
{
// Notice the next line doesn't allow you to provide contextual info.
bool rethrow = ExceptionPolicy.HandleException(ex, "Some Policy");
if (rethrow)
{
throw;
}
}
how can I pass extra contextual information to the Exception Handling
block so I can make more user-friendly exceptions.
Here is an example where I'd like to add contextual info. I have a 3rd
party report engine that throws exceptions. I'd like to wrap that
exception in a more user-friendly exception. If I open a report file
that I assume exists, and it doesn't exist, the ReportEngine will throw
an exception. But the message is too generic and not the most
user-friendly. I'd like to wrap it in some new exception that would
have some message that says: "Unable to open report file
'SomeReport.rpt'".
The problem is, to use the exception handling block, you call
ExceptionPolicy.HandleException(), but the only parameters are the
exception and the policy name. It seems like the message of the
wrapping exception is "hard coded" in the configuration file.
Have any of you users of the Exception Handling Application Block tried
to do something similar to what I want? If so, how did you handle it.
Thanks.
try
{
ReportEngine engine;
engine.OpenReport("SomeReport.rpt");
}
catch( ReportEngine.FileNotFoundException ex )
{
// Notice the next line doesn't allow you to provide contextual info.
bool rethrow = ExceptionPolicy.HandleException(ex, "Some Policy");
if (rethrow)
{
throw;
}
}