Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exception Handling Question - Again
Message
From
22/10/2009 19:19:35
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01430826
Message ID:
01430834
Views:
44
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?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform