Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Anything Wrong with Creating An ExceptionOccurred Event
Message
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01417957
Message ID:
01418317
Vues:
43
>>>All,
>>>
>>>I have some general purpose classes that I use that are stand-along DLL's and non visual components, such as my SqlDataAccess
>>>class.
>>>
>>>In this class I have an exception property that is defaulted to null. If an exception occurs, I store the exception to the property. Then it's up to the process that instantiated my SqlDataAccess class to continually check to see if the property is no longer null:
>>>
>>>
>>>SqlDataAccess data = new SqlDataAccess()
>>>data.ConnectionString = MyConnString;
>>>
>>>SqlDataReader rdr = data.ExecuteReader(ProcName, colParams, CommandType.StoredProcedure);  
>>>
>>>if(data.Exception != null)
>>>{
>>>    // Use the reader here
>>>}
>>>else
>>>{ 
>>>    // App.HandleException(data.Exception);
>>>}
>>>
>>>
>>>
>>>This if() might not be necessary of the class raised an event when an exception occurs.
>>>
>>>I dunno, what do you guys think?
>>
>>An event would work but, in either case, you're still relying on the calling method to either check the variable or handle the event and there's no guarantee that it will do this.
>
>>>I don't understand why you are not using standard exception handling for this? You can handle the exception in the calling method >>but if you forget to (or can't) do so at least it will be trapped at the application level handler.
>
>Could you explain what you mean by "standard exception handling"?

Hi,
See http://msdn.microsoft.com/en-us/library/ms173160.aspx and links therefrom. Or maybe this for an overview:http://www.c-sharpcorner.com/UploadFile/rajeshvs/ExceptionHandlinginCSharp11282005051444AM/ExceptionHandlinginCSharp.aspx
HTH,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform