Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exception Handling Question - Again
Message
De
23/10/2009 09:44:17
 
 
À
23/10/2009 00:22:49
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01430826
Message ID:
01430989
Vues:
39
Same here. BTW, that would make an excellent article!!!! :o)



>>Coming from you that makes me feel much better! Thanks!
>
>You're welcome! There are other options as well, obviously.
>
>I probably should have mentioned this in my first reply, but the main downside to this solution is that all your calls to these methods need to remember to check the oException property ... so all your developers need to be aware of this or it could cause problems.
>
>Our Framework initially worked this way (in fact, I've frequently posted some code for a DataAccess base class that does this, or something similar), but as we hired more and more developers, we wanted something a little more fool-proof; so we ended up refactoring to utilize anonymous delegates. I don't have any sample of that methodology thrown together at this time, but perhaps I should do that some day.
>
>~~Bonnie
>
>
>>
>>
>>
>>>There are probably many different "right ways" ... your solution is perfectly ok.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>
>>>>I few weeks ago I asked a question about using an event to handle exceptions. Here's a follow up.
>>>>
>>>>Assume I have this method in my Data Access class:
>>>>
>>>>
>>>>public int ExecuteNonQuery(string sCommand, ArrayList colParams, CommandType Type)
>>>>{
>>>>    int iRetVal = 0;
>>>>
>>>>    SqlConnection oConn = _GetConnection(true);
>>>>
>>>>    if (oException == null)
>>>>    {
>>>>        SqlCommand oCommand = new SqlCommand();
>>>>        oCommand.CommandText = sCommand;
>>>>        oCommand.Connection = oConn;
>>>>
>>>>        if (colParams != null)
>>>>        {
>>>>            SqlParameter[] aParams = new SqlParameter[colParams.Count];
>>>>            colParams.CopyTo(aParams);
>>>>
>>>>            oCommand.Parameters.Clear();
>>>>            oCommand.Parameters.AddRange(aParams);
>>>>        }
>>>>
>>>>        oCommand.CommandType = Type;
>>>>
>>>>        try
>>>>        {
>>>>            iRetVal = oCommand.ExecuteNonQuery();
>>>>        }
>>>>        catch (SqlException e)
>>>>        {
>>>>            _oException = e;
>>>>        }
>>>>        finally
>>>>        {
>>>>            if (oConn.State == ConnectionState.Open)
>>>>            {
>>>>                oConn.Close();
>>>>            }
>>>>        }
>>>>
>>>>        if (_oException == null)
>>>>        {
>>>>            oCommand.Parameters.Clear();
>>>>        }
>>>>
>>>>    }
>>>>
>>>>    return iRetVal;
>>>>}
>>>>
>>>>
>>>>You can see that this class uses a try/catch blocks to trap exceptions. If an exception is caught it is stored to the oException property. Then in the class that uses this I can check to see of the oException property is no longer null.
>>>>
>>>>What's the right way to do this?
.·*´¨)
.·`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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform