如何同时捕获sql异常和另一个异常 [英] how to catch both the sql exception and the other exception

查看:203
本文介绍了如何同时捕获sql异常和另一个异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


在上面,我需要确定它是否是sql异常,它应该加载mail()函数,并且是否还有其他类型的异常,它应该打印一条消息,这是我的目标.
我如何一次捕获两个异常


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

推荐答案

您可以捕获任何这样的异常

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);
     }

}


这篇关于如何同时捕获sql异常和另一个异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆