Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exception Handling Question - Again
Message
 
À
22/10/2009 19:19:35
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01430826
Message ID:
01430835
Vues:
35
Coming from you that makes me feel much better! Thanks!



>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?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform