Exception management in multi tier web apps
I have adesigned quite a few asp.net apps, all working almost identically.
I start off with 3 tiers
Data (Class library)
Business(Class library)
Presentation (asp.net or winforms)
I suspect many other asp.net devs design their code in perhaps the same way, or in even more tiers, if you adhere to the SOA architecture.
What im curious to know is that how do you handle exceptions in your asp.net apps, and how do you display information to the user? Do you use custom exceptions? Where in the tiered design do you log the exceptions?
I use this design:
Datatier:
try
...here i create db object, make query
catch
throw
finally
...close db connection dispose db object
Businesstier:
try
...I call my shared datatier method and returns either datareader or dataset
catch
throw new applicationexception("An error occured when trying to save the user",ex)
...I wrap the exception and deliver a text message to the user including the inner exception
presentationtier:
try
...some action like pressing a button
catch
logexception(ex) <--i use the logging component to log the exception and all its inner ones
showmessagebox(ex.message) <----javascript messagebox
There you have it... what do you think of this design? Should I perhaps log the exception in the business tier?
How do you other pros write your exception management architecture?
kind regards
Henrik
Re: Exception management in multi tier web apps
I guess no one likes exceptionmanagement eh :wave:
Come on, any architects here?
/Henrik
Re: Exception management in multi tier web apps
Generally, data layers should swallow errors, log them, and then rethrow them.
An error related to a data error that involves a custom object, like Registrant ie, should throw an InvalidRegistrant error (custom errors).
On the business side, again, custom objects should have their own custom exceptions.
Re: Exception management in multi tier web apps
Hi MrNorth,
I only handle the errors at each level, logging them, and then re-throwing them if necessary.
I have a question regarding the 'multi-tier' approach we use here:
http://www.vbforums.com/showthread.php?t=327915
Any input would be much appreciated
Many thanks
Nick