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
What are c# types?
What is command object in c#?
What is nameof c#?
What is the base class of all classes in c#?
What is the difference between interface and inheritance in c#?
What is response redirect in c#?
What is console read in c#?
What is the signature of a method?
What is executenonquery c#?
When should we use delegates in c#?
What is difference between continue and break in c#?
What is c# and why it is used for?
What are the differences between events and delegates in c#?
What is a web service in c#?
Explain the various types of classes used in c#?