Sunday, 17 April 2011

Is it valid to have a try block without catch or finally?

NO. This will result in a compilation error. The try block must be followed by a catch or a finally block. It is legal to omit the either catch or the finally block but not both.
e.g. The following code is illegal.
try{
int i =0;
}
int a = 2;
System.out.println(“a = “+a);

No comments:

Post a Comment