Alex Rivera | Logout

Are Try Catches still useful?

Asked 2009-04-13T13:43:47.240
9

When I first started programming in .NET I used try/catches all the time. I am finding lately though I rarely ever use them for web applications. My exception (no pun intentended) is unmanaged code that could potentially create a memory leak such as com objects. Are they really needed anymore or do they just clutter things up?

UPDATE: Assume custom errors are being used to take care of the ugly stack trace page.

Edit
Report

1 Answer

2

Exception handling logic is still plenty useful in the web domain when used in the right places. Your back-end code may need to connect to a database, communicate with a different service, or call your own exception-throwing logic. In any of these cases, you'll want to catch an exception and communicate that to the user.

For instance, let's say you need to communicate with a database that is down. You'll want to send that information back to the client page to inform the user your site is currently down or experiencing problems. Unless ALL of your external calls return friendly status codes (which is highly unlikely and cumbersome), you'll need to rely on exceptions.

answered 2009-04-13T13:48:11.457

Your Answer