Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Catch ex As Exception
           
            Dim messge = ex.Message.ToString() + strRpt + strRptType
            ''messge = messge + " :::" + ex.InnerException.ToString()
            Dim types As String = "(monthly report)"

            createErrorFileName(strRpt, types)
            ErrorLog(StartupName(), messge)
            '    MsgBox(messge)
            'Mail()
            'Return True
        Finally
            Timer1.Start()
            'Mail()

        End Try

in the above i need to identify if its an sql exception it should load the mail() function, and also if its any other type of exception it should print an message this is my objective.
how do i catch two exceptions at a time
Posted
Updated 25-Dec-11 18:27pm
v2
Comments
Sam Anthwal 26-Dec-11 0:00am    
check the InnerException Property of Exception class
EG: if(ex.InnerException==SqlException)
ashok_89 26-Dec-11 0:08am    
its giving an error sqlexception is a type and cannot be used like an method

1 solution

You can catch any no of exceptions like this

  public void  showexception()
  {
    try
    {
      ----
      ----    //Code block 
      ---
    }

    catch (SqlException e)
     {
        Console.WriteLine("Sql exception" + ex);
     }
     catch (Exception ex)
     {
        Console.WriteLine("An exception occurred (Other type)" + ex);
     }

}
 
Share this answer
 
v2
Comments
ashok_89 26-Dec-11 1:19am    
thanks a lot sir it works, thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900