Exception Handling is similar to java syntax. First, let's talk about the exception classes used in it. These exception classes are often seen during java programming:
OverflowException: An exception caused by overflow due to arithmetic, type conversion, or conversion operations;
Try {checked // use the checked keyword {int i1; int i2; int num; i1 = 5000000; i2 = 5000000; num = i1 * i2 ;}} catch (OverflowException) {Console. writeLine ("OverflowException exception thrown ");}
* ******* The checked keyword is always being checked. An exception is caught when overflow is found;
DivideByZeroException: An exception occurs when the divisor is 0;
FormatException: An exception occurs when the input format does not meet the specifications;
ArithmeticException: An exception occurred during arithmetic operations;
IndexOutOfRangeException: An exception occurs when coordinates smaller than 0 or beyond the array limit are used;
NullReferenceExcption: an exception that occurs when the object to be referenced is null;
The bottom two exceptions are often seen when writing java programs...
I see an example of custom exception output in my book. I feel that the exception handling process is relatively simple:
Class Sec {public int myint (string a, string B) {int int1, int2, num; try {int1 = int. parse (a); int2 = int. parse (B); if (int2 = 0) {throw new DivideByZeroException (); // if the denominator is 0, an exception is thrown.} num = int1/int2; return num ;} catch (DivideByZeroException de) // catch exceptions {Console. writeLine ("an exception is thrown when a zero-division integer is used! "); Console. writeLine (de. message); return 0 ;}} static void Main1 (string [] args) {try {Console. writeLine ("Enter the molecule:"); string str1 = Console. readLine (); Console. writeLine ("Enter denominator:"); string str2 = Console. readLine (); Sec sec = new Sec (); Console. writeLine ("numerator divided by denominator:" + sec. myint (str1, str2);} catch (FormatException) {Console. writeLine ("Please enter the value format data ");}}}
This article from "tired also happy D" blog, please be sure to keep this source http://zhangzhang.blog.51cto.com/6250085/1261637