+ 1
explain in detail...how to work try and catch block??
5 ответов
+ 2
Thete is a good explanation in java course.
Here is an example:
public class MyClass {
public static void main(String[ ] args) {
try {
int a[ ] = new int[2];
System.out.println(a[5]);
} catch (Exception e) {
System.out.println("An error occurred");
}
}
}
+ 2
What do u mean by "exception e"?^
0
try block identifies where exception is occurs and the catch block is used to handle that exception. we put the exception prone statements in try block.
0
"Exception e" is a formal parameter to receive actual parameter. try block throw the object of related exception class we have to receive this object in reference variable of same exception class or of it's parent class.
0
it is not mandatory to write Exception e.. instead you can write exact the type of Exception like Arithmetic Exception and e is a reference.you can put your name also .WITHIN print just print the reference