- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHi everybody,
I have created custom exception handler by implmenting IExceptionHandler. I wrote a code how to invoke the custom exception hander as follows and it is working as expected.
try
{
// Some code processing
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleExce
if (rethrow)
{
throw;
}
}
My question is: How could I automatically catch ANY exception within MyCustomExceptionHander?
e.g in the attached code, what if the error is thrown outside of catch block? How to catch "Some exception here" in MyCustomExceptionHandler.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: SteveH_UKPosted on 2009-06-15 at 05:51:01ID: 24628278
In your code, the exception is passed to the first method in the call stack (the chain of method invocations that reach the currently executing code) until an appropriate exception handler is found. This means that you just need to ensure that the calling method (or one of its callers) has an exception handling block.
In general, you shouldn't try and catch exceptions that you aren't expecting. These can be caused by faults that are difficult to recover from such as low memory conditions, disk corruption and so on.
There are a couple of exceptions to this rule:
1) It can be helpful to ensure logging of all unhandled exceptions. Windows does this automatically but if you need a custom logger then you'll need your code to be executed. You still have the option of rethrowing the exception.
2) Your code may not be the whole application, such as with ASP.NET or WCF. In these cases, you can use API extensions to support exception handling automatically. The ExceptionShielding pattern is used in the Microsoft Enterprise Library to achieve this for WCF solutions.
Finally, there is no possibility of catching an exception except by using an API extension (which uses try-catch itself) or try-catch directly. If you are trying to do that, the chances are you are attempting to solve the wrong problem.
Can you give more details if I haven't answered your question?