Catching Exception inside Using statement

后端 未结 9 691
不知归路
不知归路 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:03

    You don't do it inside the using

    try
    {
        using(SqlConnection conn = new SqlConnection(connString))
        {
            // Some code for when "conn" is succesfully instantiated
        }
    }
    catch (SomeSpecificConnectionInstantiationException ex)
    {
        // Use ex to handle a bizarre instantiation exception?
    }       
    

提交回复
热议问题