添加两个必要的catch块语句,这些语句应该用于处理这些代码通常遇到的常见错误。 [英] Add two necessary catch block statements that should be used to handle common errors that are usually encountered with such codes.

查看:68
本文介绍了添加两个必要的catch块语句,这些语句应该用于处理这些代码通常遇到的常见错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Program
{
static void Main(string[] args)
{
Console.Write("Please enter two numbers: ");
try
{

double num1 = double.Parse(Console.ReadLine());
double num2 = double.Parse(Console.ReadLine());
double result = num1 / num2;
Console.WriteLine("{0} / {1} = {2}", num1, num2, result);
}
catch ??
catch ??
Console.ReadKey();
}
}





我的尝试:



我是空白这是关于catch语句和异常处理的赋值问题。伙计们请帮帮我。



What I have tried:

I'm blank this is a assignment question about catch statements and exception handling. Guys please help me out.

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



阅读尝试...抓住块,然后看看你的情况。

亲自尝试一下,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Read up on try...catch blocks, and see what you and work out.
Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


虽然我不打算给你这个相对容易的问题的答案;我会尽力指导你...



你通常会看到这个脚本抛出什么类型的异常?如果你不知道,尝试运行它没有任何尝试...捕获循环并测试它具有良好的值,坏的值,没有值等....



一旦你测试了这个,你应该有一个输入导致什么例外的列表。无论前两个例外最有可能是您需要捕获的。
While I am not going to give you the answer to this relatively easy question; I will try to guide you...

What types of exceptions would you generally see thrown with this script? If you do not know, try running it without any try...catch loops and test it out with good values, bad values, no values, etc....

Once you have tested this out, you should have a list of what input causes what exceptions. Whatever the top two exceptions are most likely will be the ones that you need to catch.


double.Parse



那么上面的行会抛出什么样的异常?提示:查看文档。


So what sort of exception could the above line throw? Hint: look at the documentation.

double result = num1 / num2;



num2的值可能会导致抛出异常?


And what value of num2 could cause an exception to be thrown?


这篇关于添加两个必要的catch块语句,这些语句应该用于处理这些代码通常遇到的常见错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆