|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Enterprise Library Exception Handling Application Block - adding context to exceptionshow 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; } } You don't have to, you can throw your own exception derived objects and it
will still be caught by the enterprise library. -- Show quote________________________ Warm regards, Alvin Bruney [MVP ASP.NET] [Shameless Author plug] Professional VSTO.NET - Wrox/Wiley The O.W.C. Black Book with .NET www.lulu.com/owc, Amazon Blog: http://www.msmvps.com/blogs/alvin ------------------------------------------------------- <clint***@fflax.net> wrote in message news:1148681526.099378.273650@y43g2000cwc.googlegroups.com... > 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; > } > } > Alvin,
Thanks for the reply. But I'm a little confused by your response. The catch block in the sample I gave could throw my own exceptions, but I want a exception handling policy to do that for me. I was hoping to call a "report exception" handling policy that would wrap the 3rd party report engine message and wrap it in one of my user-friendly exceptions. But to make a user-friendly message, I wanted to provide more info. In my example, I wanted to pass along the report path. - Clint Alvin Bruney wrote: Show quote > You don't have to, you can throw your own exception derived objects and it > will still be caught by the enterprise library. > > -- > > ________________________ > Warm regards, > Alvin Bruney [MVP ASP.NET] > > [Shameless Author plug] > Professional VSTO.NET - Wrox/Wiley > The O.W.C. Black Book with .NET > www.lulu.com/owc, Amazon > Blog: http://www.msmvps.com/blogs/alvin > ------------------------------------------------------- > > <clint***@fflax.net> wrote in message > news:1148681526.099378.273650@y43g2000cwc.googlegroups.com... > > 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; > > } > > } > > The exception handling policy in the Enterprise library is for catching
exceptions. The framework is not concerned with throwing exceptions. So basically, you wrap your exceptions however you want to wrap it and provide what ever message you feel is appropriate and then throw it. Then you tweak the aspects container to catch that type of exception and do something with it. -- Show quote________________________ Warm regards, Alvin Bruney [MVP ASP.NET] [Shameless Author plug] Professional VSTO.NET - Wrox/Wiley The O.W.C. Black Book with .NET www.lulu.com/owc, Amazon Blog: http://www.msmvps.com/blogs/alvin ------------------------------------------------------- <clint***@fflax.net> wrote in message news:1148999882.855694.299770@g10g2000cwb.googlegroups.com... > Alvin, > Thanks for the reply. > > But I'm a little confused by your response. The catch block in the > sample I gave could throw my own exceptions, but I want a exception > handling policy to do that for me. > > I was hoping to call a "report exception" handling policy that would > wrap the 3rd party report engine message and wrap it in one of my > user-friendly exceptions. But to make a user-friendly message, I > wanted to provide more info. In my example, I wanted to pass along the > report path. > > - Clint > > > Alvin Bruney wrote: >> You don't have to, you can throw your own exception derived objects and >> it >> will still be caught by the enterprise library. >> >> -- >> >> ________________________ >> Warm regards, >> Alvin Bruney [MVP ASP.NET] >> >> [Shameless Author plug] >> Professional VSTO.NET - Wrox/Wiley >> The O.W.C. Black Book with .NET >> www.lulu.com/owc, Amazon >> Blog: http://www.msmvps.com/blogs/alvin >> ------------------------------------------------------- >> >> <clint***@fflax.net> wrote in message >> news:1148681526.099378.273650@y43g2000cwc.googlegroups.com... >> > 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; >> > } >> > } >> > > |
|||||||||||||||||||||||