//C# - DivideByZeroException Exception Example. using System; class ExceptionDemo { static void Main(string[] args) { int a = 10; int b = 0; int c = 0; try { c = a / b; Console.WriteLine(c); } catch (DivideByZeroException e) { Console.WriteLine(e.Message); } } } ...
大家可能认为会引发DivideByZeroException异常,实际上并不会,C#的编译器会检测出这个问题来,直接产生编译错误:被常数零除。你直接除以0,编译器这一关就通不过的。 2, int i = 5; int j = j / (i-5); Console.WriteLine(j); 这次编译器已经 不能发现问题了,会产生DivideByZeroException异常。 3,下面我们...
public class DivideByZeroException : ArithmeticException繼承 Object Exception ArithmeticException DivideByZeroException 範例下列範例會處理 DivideByZeroException 整數除法中的例外狀況。C# 複製 執行 using System; public class Example { public static void Main() { int number1 = 3000; int number2 = 0;...
Initializes a new instance of the DivideByZeroException class with a specified error message and a reference to the inner exception that is the cause of this exception. Namespace: System Assembly: mscorlib (in mscorlib.dll) Syntax VB 複製 'Declaration Public Sub New ( _ message...
Steps to handle type exception in Python The steps to handle type exception in Python are: Step 1:We will take inputs from the user, two numbers. Step 2:If the entered data is not integer, throw an exception. Step 3:If the remainder is 0, throw divide by zero exception. ...
In this example, a method tests for division by zero and catches the error. Without the exception handling, this program would terminate with aDivideByZeroException was unhandlederror. C#Copy publicclassExceptionTest{staticdoubleSafeDivision(doublex,doubley){if(y ==0)thrownewDivideByZeroException(...
Learn about exceptions and exception handling. These C# features help deal with unexpected or exceptional situations that happen when a program is running.
The exception that is thrown when there is an attempt to divide an integral or Decimal value by zero.
The exception that is thrown when there is an attempt to divide an integral or Decimal value by zero.
case DIVIDE_BY_ZERO: printf("a division by zero occurred\n"); break; default: printf("some other error occurred\n"); break; case XFINALLY: printf("cleaning up\n"); } XUnLinkExceptionRecord(&XData); } Example 2:setjmp()/longjmp()-based error handling with exception records allocated on...