How to handle exception without using try catch?

jams picture jams · Apr 24, 2012 · Viewed 17.2k times · Source
using (SqlConnection con = new SqlConnection())
{
     try
     {
          con.Open();
     }
     catch (Exception ex)
     {
          MessageBox.Show(ex.Message);
     }
}

This works fine. But I want to know can we handle exception without using try catch like some thing if else? Or is it mendetory to use try catch.

Answer

Tejs picture Tejs · Apr 24, 2012

There is no other mechanism to handle an exception other than try catch. It sounds like you want something like

if(connection.DidAnErrorOccur)

but that doesn't exist.