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 is addressof operator?
Explain acid rule of thumb for transactions in c#.
Is c# 8 released?
What does ienumerable mean?
What is multithreading with .net?
What is response redirect in c#?
Explain about Threading Types.
What are virtual destructors?
What is a byte in c#?
What does console mean c#?
What is an array class?
Does c# provide copy constructor?
What are the desktop applications?
What is a collection class in c#?
What is event sourcing in c#?