对了,ret_msg是已经定义好了的

解决方案 »

  1.   

    哈哈
    你在catch 后又抛出了一个一样的异常,当然有未处理的异常了public bool Check(int a)
    {
        try
        {
    if(a>0)return true;
    else throw new Exception(ret_msg);
         }
        catch(Exception ex)
        {
            //throw ex;
            //这里应该是错误处理语句
        }
    }
      

  2.   

    catch里要捕获自己定义的异常,不要用System.Exception
      

  3.   

    because your rethrew it?!public bool Check(int a)
    {
        try
        {
    if(a>0)return true;
    else throw new Exception(ret_msg);
         }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
      

  4.   

    但是如果
     try
        {
    if(a>0)return true;
    else throw new Exception(ret_msg);
             ...
             ...
         }
        catch(Exception ex)
        {
            throw ex;
        }其中的"..."表示还有其它代码,我并不在那中间自己throw exception呢?这个时候就需要catch块里面来throw这些异常了
      

  5.   

    public bool Check(int a)
    {
        try
        {
    if(a>0)return true;
    else throw new Exception(ret_msg);
         }
        catch(Exception ex)
        {
           // throw ex;
            MessageBox.Show(ex.ToString());
        }
    }
      

  6.   

    你在catch(Exception ex)时就捕获到了异常
      

  7.   

    public bool Check(int a)
    {
        try
        {
    if(a>0)return true;
    else throw new MyException(ret_msg);
         }
        catch(Exception ex)
        {
           // throw ex;
            MessageBox.Show(ex.ToString());
        }
        catch(MyException ex2)
        {
           ...
        }
    }
    //自定义自己的异常处理类
    public class MyException : Exception
    {
    ....
    }
      

  8.   

    我并不需要MessageBox.Show(ex.ToString());,而是想将这个异常继续传递到上层的代码,所以才在catch里面用throw的
      

  9.   

    异常应该在 try 部分抛出,在 catch 部分得到处理