你把你捕捉到的异常写进你log日志里不就行了么try
{
   //TODO: your code
}
catch(Exception ex)
{
   // Throw the exception
}

解决方案 »

  1.   

    使用Try块把可能出现异常的语句块包起来,在Catch中捕获和处理异常,把写日志、关闭资源等操作写在Catch中,将那些在异常出现时一定要执行的语句放在Finally语句块中!try
    {
    //可能发生异常的语句
    }
    catch(Exception)
    {
    //捕获异常,catch语句可以多级嵌套,以实现精准的异常捕获
    }
    finally
    {
    //一定要执行的语句放在这里,例如关闭文件等
    }
      

  2.   


    try
    {
    //可能发生异常的语句
    }
    catch(Exception)
    {
    //捕获异常,写如日志
       write.log();
    }
    finally
    {
    //一定要执行的语句放在这里,例如关闭文件等
    }
      

  3.   

    '-----写日志方法:-----------
    Public Shared Function errLog(ByVal err As String) As String
                Try
                    '写入数据库日志表
                    
                Catch ex As Exception
                    '写入windows event log
                End Try        End Function
    '-----调用:------------
    Try
    Catch ex As Exception
         Utility.errLog("Webpage error log in " + Request.RawUrl() + "(user:" + Session("loginid") _
                + "; IP:" + Request.ServerVariables("REMOTE_ADDR") + ") - " + ex.ToString())
    End Try
      

  4.   

    void Do1(){ .... }
    void button1_Click(object sender,EventArgs e){
    TryNoDebug(Do1);
    }class Common{
    static void TryNoDebug(MethodInvoker method){
    if(Debugger.IsAttached){
    method();
    }else{
    try...
    }
    }
    }
      

  5.   

        class Program
        {
            public static void Main(string[] args)
            {     
                try
                {            }
                catch (OtherException1 e)
                {
                    throw new OtherException1();
                }
            }
        }    class OtherException1 : Exception
        {
            public OtherException1()
            {
                //写日志1
                throw new Exception("OtherException1");
            }
        }    class OtherException2 : Exception
        {
            public OtherException2()
            {
                //写日志2
                throw new Exception("OtherException2");
            }
        }