Catching Exception inside Using statement

后端 未结 9 699
不知归路
不知归路 2021-02-04 01:27

I know that Using statement disposes out the object that is being created. Like if I wanted to do something like this:

    Using(SqlConnection conn = new SqlConn         


        
9条回答
  •  你的背包
    2021-02-04 02:02

    Just in the normal way:

    Either

    try
    {
        using(SqlConnection conn = new SqlConnection(connString)) 
        { 
          //some code        
        } 
    }
    catch (Exception exc)
    {
        //handle error
    }
    

    or

    using(SqlConnection conn = new SqlConnection(connString)) 
    { 
        try
        {
            //some code 
        }
        catch (Exception exc)
        {
            //handle error
        }                
    } 
    

提交回复
热议问题