If I have a layered application and my Data Layer may encounter an OptimisticConcurrencyException how should the calling layer or indeed the lower layer deal with this??
The calling layer has no idea what an OptimisticConcurrencyException is, so should I be implementing a custom exception and catching the OptimisticConcurrencyException and throwing my Custom Exception?
Some guidance on this would be greatly appreciated.
In the data access layer, the generic exception handling accounts for 93.50% (15,929) of the violations.
try catch finally 2. Use error events to deal with exceptions within the scope of an object. Page_Error Global_Error Application_Error 3. Use custom error pages to display informational messages for unhandled exceptions within the scope of a Web application.
Exception handling is the process of responding to unwanted or unexpected events when a computer program runs. Exception handling deals with these events to avoid the program or system crashing, and without this process, exceptions would disrupt the normal operation of a program.
OptimisticConcurrencyException
is an exception that belongs to the data layer and should therefore be contained within it. It's unlikely that calling layer could handle it.
I would create a more generic exception such as DataSourceException
which would contain some context such as which function failed (and with which parameters) and why. I would also include the original exception as inner exception.
Read my blog entry about catching exceptions: http://blog.gauffin.org/2010/11/do-not-catch-that-exception/
I've also written some other entries about exception handling, click on the Exception tag.
Update
I would create the following projects:
You need to look at this from the perspective of the calling layer. The layer has asked the data layer to perform a job. If the OptimisticConcurrencyException
can be handled by your data layer and the contract adhered to, then by all means catch it and then carry on and complete the job.
If, however, this is fatal to the job you're being asked to do, and if the caller is not expecting it, or doesn't know it, then it's fine for you to create your own exception class, catch the exception that is alien to the calling layer, and throw that instead. This is something that the calling layer can know about, and can be well-documented as a side-effect of using this function/API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With