且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DivideByZeroException代码漏洞

更新时间:2023-09-11 21:53:16

这里有语法错误:
Console.WriteLine("End";);

额外的分号将阻止编译。



结构错误是你的第一个异常捕获是将捕获所有错误,并处理它们,因此编译器不知道该做什么与第二个catch,并将导致此错误:前一个catch子句已经捕获了这个或超类型的所有异常( 'System.Exception')



如果你把更具体的catch子句用于之前的除零错误 - 所有catch子句,这将工作:

The extra semi-colon will prevent compiling.

The structural error is that your first catch of the exception is going to catch all errors, and handle them, so the compiler "doesn't know what to do" with the second catch, and will cause this error: "A previous catch clause already catches all exceptions of this or of a super type ('System.Exception')"

If you put the more specific catch clause for a divide-by-zero error before the catch-everything catch clause, this will work:

catch (DivideByZeroException ex)
{
    Console.WriteLine("DivideByZeroException");
}
catch (Exception ex)
{
    Console.WriteLine("Exception");
}


这不是CP通常的工作方式。这里最重要的目标是学习和帮助学习。

你应该自己尝试,当你遇到困难时来到这里,对你的代码,设计等有一个具体的问题。

请查看你有什么尝试? [ ^ ]至看看我的意思是一个很好的解释。

不要忘记这里的人不会得到报酬。此外,如果我们给你一个随时可用的解决方案,它不会帮助你,因为你不会从中学到任何东西。



In另外,我们不会家庭作业 [ ^ ]



您可以尝试猜测并解释它,然后问问题,你会得到你的答案......你发布的内容意味着:请为我做我的工作
This is not how CP usually works. Most important goal here is to learn and help learning.
You are supposed to try it on your own, and come here when you got stuck with something, with a concrete question about your code, design, etc.
Please have a look to What have you tried?[^] to see a good explanation about what I mean.
Don't forget people here don't get payed. And besides, if we give you a ready-to-go solution, it is not going to help you because you are not going to learn anything from it.

In addition, we don't do Homework[^]

You can try it giving a guess and an explanation of it, then ask something and you will get your answers... What you posted means: "please do my work for me"