How to handle a specific exception
using System;
class MainClass{
public static void Main() {
try {
int zero = 0;
Console.WriteLine("In try block: attempting division by zero");
int myInt = 1 / zero;
} catch (DivideByZeroException myException) {
Console.WriteLine("Message = " + myException.Message);
Console.WriteLine("StackTrace = " + myException.StackTrace);
}
}
}
Output In try block: attempting division by zero
Message = Attempted to divide by zero.
StackTrace = at MainClass.Main()
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
-
-
-
-
|