Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exception Handling Question - Again
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01430826
Message ID:
01430827
Views:
37
In your code you're referencing oException and _oException. How this property is defined in the class?

>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?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform