比如,用户输入一个数,如果这个数大于10,就产生异常。 在C#是怎么样写的?try
{
int a = Convert.ToInt32(Console.ReadLine());
}
catch
{
}
finally
{
}
{
}

解决方案 »

  1.   

    如果是大于10了。我怎么样,让catch可以捕获得呢?
      

  2.   

    try
    {
    int a = Convert.ToInt32(Console.ReadLine());
    if(a>10)
    throw new Exception();
    }
    catch(Exception ex)
    {
    Console.WriteLine("大于10");
    }
    finally
    {
    //
    }
    {
    }
      

  3.   

    try 

    int a = Convert.ToInt32(Console.ReadLine()); 
    if(a>10) 
    throw new Exception("用户输入不能大于10"); 

    catch(Exception ex) 

    Console.WriteLine(ex.Message); 

    finally 

    // 


    }
      

  4.   

    if(a > 10)
    {
    throw(a);
    }这样行不行?
      

  5.   

    try 

    int a = Convert.ToInt32(Console.ReadLine()); 
    if(a>10) 
    throw new Exception("用户输入不能大于10"); 

    catch(Exception ex) 

    Console.WriteLine(ex.Message); 

    finally 
    {
    throw new  Exception("新的throw");//会执行吗?
    // 


    }
      

  6.   

    try 

    int a = Convert.ToInt32(Console.ReadLine()); 
    if(a>10) 
    throw new Exception("用户输入不能大于10"); 

    catch(Exception ex) 

    Console.WriteLine(ex.Message); 

    finally 

    throw new  Exception("新的throw");//会执行吗?上几行的catch会得到throw出的异常吗?
    // 


    }
      

  7.   

    finally是不管有没有异常始终执行的语句
      

  8.   

    代码如下 :try
    {
    }catch(Exception e)
    {
    Console.WriteLine(e.Message);
    }throw new Exception("A");
    throw new Exception("B");
    throw new Exception("C");会输出吗?代码由上至下执行。
      

  9.   

    throw new Exception("A"); 
    throw new Exception("B"); 
    throw new Exception("C"); 
    这里抛出了三个异常。必须得用try catch来捕获。如果没有捕获那么程序运行时就会在此处出现异常
      

  10.   

    先自定义一个异常MyExceptionclass MyException:Exception
    {
     public MyExcetpion(){}
    }class Test
    {
       try
       {
       if(input>10)
       {
         throw new MyException();
       }
       }
       catch (MyException e)
       {}
       finally{}
    }
      

  11.   

    public void Getv(int i)
    {  
       if(i>10)
         throw new Exception("输入数太大");     
    }
    void Test(){   try{
          Getv(20);
       }
       catch(Exception e)
       {
         MessageBox.Show(e.Message);
       }
    }设计时用throw,调用时放入try块