Exception handling using the HttpModule

We review one of the system exceptions for the system and discover a couple of interesting things.

Most blocks of code (if not all of them) are inside the try / catch block, and inside the catch block, a new BaseApplicationException is thrown, which seems to come from corporate libraries. I have a bit of a problem here, since I don't see the benefits of this. (throwing another exception at any time) One of the developers who used this system for a while said because this class is responsible for posting the exception (sending emails and the like), but he was not too sure about it. After spending some time looking at the code, I am pretty sure that all he does is gather information about the environment and publish it.

My question is: - Is it wise to wrap all the code inside try {} catch {} blocks and throw a new exception? And if so, why? What is the use?

My personal opinion is that it would be much easier to use the HttpModule, register for the Error event of the Application event, and do what is needed inside the module. If we take this road, will we miss something? Any flaws?

Your feedback is greatly appreciated.

+5
source share
6 answers

Never 1catch (Exception ex) . Period 2 . It is impossible to handle all kinds of errors that you can catch.

3 , Exception, ( ). .

, :

  • -

, ( reset ), . ( .)

, , . WinForms System.AppDomain.CurrentDomain.UnhandledException, - Threading - System.Windows.Forms.Application.ThreadException. - (System.Web.HttpApplication.Error).

() (.. throw new MyBaseException(ex);): . 4


Edit

1 , , @Chris . , , .

2,3 . 1.

4 , . Exception ex , , , , , . , , .

+10

, , try/catch, ( - ?) , , .

:

, - , , , - .

Exception, , OutOfMemory StackOverflow, , , , .

:

, (, , ) , , , .

, .

, , - , - , , B .. , . , , , , .

+2

ELMAH. , . .

, . , , sql. TONS SQL- , . . , , , , RepositoryException, .

, . , , catch.

, , . , , RepositoryException . , catch . , .

+1

, , , .

, , , BaseApplicationException , , . , , EntityNotFoundException. , , . BAseApplicationException (, ), .

HttpModule , , . , HETModule OnError switch BaseApplicationexception.

, , , .

0

, , Server (?). .NET , - , .

0

All Articles