c# - General Exception Handling Strategy for .NET -


I am used to try / hold blocks in each method. The reason for this is that I can log on and catch every exception at the point of exclusion. I think, with my reading and conversation with others, this is not a popular scene. One should catch the one who is ready to handle someone, however, if I do not catch the issue of obstruction, then it is possible to never enter that barrier and find out about it. Note: When I catch and do not handle, I still throw it, it allows me to induce an exception to do something which will handle it, still I still have permission to login at the point of its violation gives.

So ... how to avoid / try to catch in every method still log on the error on which this happened?

No, do not hold everything Exceptions promote higher on the stack. You just have to make sure that the exception is caught before moving on the stack.

This means, for example, you may have an attempt to hold an event handler / hold block an event handler, "top of the stack", as well as callback to the threadstart handler or asynchronous method.

You also want to observe exceptions on the boundaries of the layer, however in that case, you want to wrap the exception in a layer-specific exception.

ASP.NET In case of, you can decide to allow ASP.NET health monitoring to log exceptions for you.

But you never have to catch exceptions. It's a major anti-pattern in every system. I would strongly urge you to check in code with that exception handling.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -