Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exception Handling in n-tier application
Message
De
26/03/2008 04:18:09
 
 
À
25/03/2008 17:57:21
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 8.0
Divers
Thread ID:
01305376
Message ID:
01305592
Vues:
6
>>>I have been reading a few MS books and they seem to have different advice on how to handle Exceptions in a n-tier application. The Microsoft 70-536 training guide states that all code besides simple variable declarations should be included within a Try Catch block. The Framework Design Guidelines from the Microsoft Development Series states that only exceptions where you have explicit procedures to handle the specific error, and that you should never catch a base type Exception, rather, you should have the application crash.
>>>
>>>I understand the basic functionality of Exception Handling, but I am trying to find the best way do it. Before I had all of the code in the DataAccess class wrapped in a Try Catch block, where if it was a base Exception I would rethrow the exception. I would do the same thing in the BusinessLogic class, and in my UI class I would have all of the code wrapped in Try Catch blocks, but handling the exceptions appropriately. This seems to be the wrong way to go about this.
>>>
>>>Can somebody explain their Exception Handling framework? Thanks!
>>
>>It seems like part of my problem was that when I was rethrowing the exception, I would use Throw ex (which actually repackages the exception) instead of simply Throw. This keeps the original stack trace intact, which helps big time. This also seems to fit nicely in the my existing scheme. However, I still don't understand the comment that discourages from catching a generic Exception.
>
>Furthermore, I just discovered that I don't even HAVE to have a catch statement if I just want to rethrow the exception. The only reason I use Try Catch is to take advantage of Finally to close and dispose my objects, and it looks like there are other methods I can use (was it Using? I don't remember off the top of my head) to replace that functionality. If I get that figured out I don't even need a Try block unless I want to specifically want to handle an exception a certain way. However, it is nice to be able to explicitly close and dispose my objects in the Finally section.
>
>I guess I am just thinking out loud and hoping somebody benefits from this...

Hi,
'Using' is useful in a lot of cases but don't forget you can also use a finally without a catch:
 try
 {
     throw new Exception();
 }
 finally
 {
     System.Windows.Forms.MessageBox.Show("In finally");
 }
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform