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:
01418318
Vues:
42
>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?
>
>
>
>
>
>
>>>Anyone see anything wrong with create an event to raise when an exception occurs?
>>
>>Yes. This sounds like you try to implement VFP's error event. Exception handling and error event are contrary concepts that don't go very well together.
>>
>>An exception that isn't handled in your code should be passed on the calling hierarchy. I think this becomes obvious if you don't look at the simple scenario of A calling B, but A calling B calling C. If component C has an ExceptionOccured event, suddenly A and B have to subscribe to the event of component C. That means A suddenly needs to know about implementation details and calling hierarchies in component B. Or, component B would need another event that A subscribes too which passes on the exception. That would merely simulate exception handling but require a lot of code and makes it easy to break the chain accidentally.

http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx

http://books.google.com/books?id=_KmwD58sxHsC&pg=PA205&lpg=PA205&dq=data.ExecuteReader+exception+handling+c%23&source=bl&ots=BLTR7pep0U&sig=zMwykEiamxMGo4-bt7V2ySz_hcQ&hl=en&ei=UzCISva9GYantgfz89XnDA&sa=X&oi=book_result&ct=result&resnum=9#v=onepage&q=&f=false

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=128

http://www.c-sharpcorner.com/UploadFile/rajeshvs/ExceptionHandlinginCSharp11282005051444AM/ExceptionHandlinginCSharp.aspx
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform