How many catch blocks can be there for a single try block?

Answer Posted / ankita

The try block is immediately followed by zero or more catch
blocks. It means you can use as many catch blocks with one
try block. But there must be at least one catch block
following a try block, unless you are using a finally block.
For example, consider the following program:
Class Exception {
Public Static void main(string args[ ] ){
int d,a;
try { // monitor a block of code
d=0;
a=42/d;
System.out.println(*This will not be printed,*);
} catch(Arithmetic Exception) { // Catch divide-by-zero
error System.out.println(*Division by Zero*);
}
System.out.println(*After catch statement.*);
} }
This program generates the following output
Division by Zero.
After Catch Statement.

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does google use c#?

522


What is an assembly in .net?

579


What are the properties of a string class?

521


What is oledb in c#?

507


How main method is called in c#?

523






What is a method signature in c#?

515


Difference between value and reference type.

515


What you mean by inner exception in c#?

531


Is string null or empty?

519


Can you instantiate a struct without using a new operator in c#?

540


What is a decimal in c#?

508


What is the difference between gettype and typeof in c#?

455


What is using keyword?

535


Why delegates are required?

542


What are c# i/o classes? What are the commonly used i/o classes?

519