- May 27, 2002
- 12,653
- 205
- 106
So I am working on an ASP.net website software project for work.
In my VS 2012 solution, there are 3 separate projects for the N-tier layers.
we have the Data Access Layer (DAL), which is pretty much all the SQL data models and the ADO.net code to read and write to SQL Server through Stored procedures.
Then I have a Business Logic Layer, which does all the business decisions.
Finally I have the ASPX Webforms project which contains all the webpages and their respective code-behind.
What I need to make some decisions on is the best way to "bubble" my exceptions up through the layers. My goal is to log (log4net) the real exceptions at the lowest layer possible, then create my own custom wrapper exception classes, to pass up to the next layer, and finally up to the web layer for the purpose of displaying generic-but user friendly error messages.
my main point of concern is including the original exception as part of my custom exception as the inner-exception, so if I need those details in a higher layer they are available.
So lets say I get a SQLExceptionError in the DAL, and wrap it in my own DatabaseFailureException(FriendlyMsg, OriginalExceptionAsInnerException) and throw that to the Business Logic Layer. i catch it there.
Now here is my problem... do I catch that Exception and just rethrow it up to the web layer? Or should I wrap it in another wrapper exception and then throw it?
I was doing some reading, and I don't quite understand everything... However the general consensus is that if not done correctly... the InnerException gets lost OR you lost the complete Stack Trace when rethrowing exceptions through n-tier layers
Can someone explain this problem in further depth to me and then explain how can I correctly bubble up my exceptions through 3 layers but still have the relevant Stack Trace and InnerException across all 3 of my layers?
In my VS 2012 solution, there are 3 separate projects for the N-tier layers.
we have the Data Access Layer (DAL), which is pretty much all the SQL data models and the ADO.net code to read and write to SQL Server through Stored procedures.
Then I have a Business Logic Layer, which does all the business decisions.
Finally I have the ASPX Webforms project which contains all the webpages and their respective code-behind.
What I need to make some decisions on is the best way to "bubble" my exceptions up through the layers. My goal is to log (log4net) the real exceptions at the lowest layer possible, then create my own custom wrapper exception classes, to pass up to the next layer, and finally up to the web layer for the purpose of displaying generic-but user friendly error messages.
my main point of concern is including the original exception as part of my custom exception as the inner-exception, so if I need those details in a higher layer they are available.
So lets say I get a SQLExceptionError in the DAL, and wrap it in my own DatabaseFailureException(FriendlyMsg, OriginalExceptionAsInnerException) and throw that to the Business Logic Layer. i catch it there.
Now here is my problem... do I catch that Exception and just rethrow it up to the web layer? Or should I wrap it in another wrapper exception and then throw it?
I was doing some reading, and I don't quite understand everything... However the general consensus is that if not done correctly... the InnerException gets lost OR you lost the complete Stack Trace when rethrowing exceptions through n-tier layers
Can someone explain this problem in further depth to me and then explain how can I correctly bubble up my exceptions through 3 layers but still have the relevant Stack Trace and InnerException across all 3 of my layers?