函数中抛出异常让调用该函数的函数捕获,要怎样做?

解决方案 »

  1.   

    private void Method1()
    {
        try
        {
            Method2();
        }
        catch(Exception ex)
        {
            //todo ....
        }
    }private void Method2()
    {
        //to do... 这里可以捕捉,然后throw出来,或者不处理~~~~~
    }
      

  2.   

    恩。不错。那么函数后面的throw Exception是什么意思,格式是怎样的?
      

  3.   

    直接用参数Out string errMsg
    catch(Exception ex)
    {
       errMsg=ex.Message;
    }
      

  4.   

    catch (Exception ex)
                {
                    errMsg = ex.Message;
                    return null;
                }
    errMsg 为输出参数,在调用出判断errMsg是否为string.Empty
      

  5.   

    string strError = "";
    private void Method1() 

        try 
        { 
            Method2(); 
        } 
        catch(Exception ex) 
        { 
            //throw ex; 拋出異常
    strError  = es.Message;//把異常信息付給 strError  
        } 
      

  6.   

    private void Method2() 

        try
        {
            //to do... 
        }
        catch(Exception ex)
        {
            //todo .... 在这里可以处理一些额外的事情
            throw ex;//这里thorw出去,可以在Method1中接收~~~~
        }
    }
      

  7.   

    strError  = es.Message;//把異常信息付給 strError  
    throw exception方法呢?