标题:这题我真晕了```有没人帮帮忙,新手,对异处理还不会
只看楼主
smltq
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:566
专家分:400
注 册:2008-1-21
 问题点数:0 回复次数:2 
这题我真晕了```有没人帮帮忙,新手,对异处理还不会
4.打开4文件夹中的项目,请为其添加异常处理模块,使得:
<1>当输入字符串格式不对时,在控制台上输出“请输入整数”;
<2>当j=0时,在控制台上输出“除数不能为0”;
<3>当输入的数字太大时,将该异常重新抛出;
<4>当有其他异常时,在控制台上输出“其他状况”。

以下是第四题的项目文件
using System;
using System.Collections.Generic;
using System.Text;

namespace _
{
    class Program
    { static void Main(string[] args)
        {
            int i = Convert.ToInt32(Console.ReadLine());
            int j = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(i / j);
}
    }
}
搜索更多相关主题的帖子: using Console Convert System 
2008-06-17 20:03
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
得分:0 
try
{
  int i = Convert.ToInt32(Console.ReadLine());
  int j = Convert.ToInt32(Console.ReadLine());
  Console.WriteLine(i / j);
}
catch(InvalidCastException ex)
{
  Console.WriteLine("请输入整数");
}
catch(DivideByZeroException ex)
{
  Console.WriteLine("除数不能为0");
}
catch(OverflowException ex)
{
  threw ex;
}
catch(Exception ex)
{
  Console.WriteLine("其他状况");
}

Flying without wings
2008-06-17 21:07
smltq
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:566
专家分:400
注 册:2008-1-21
得分:0 
非常感谢
2008-06-18 13:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-219728-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.980903 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved