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 console application with example?
What is lastindexof c#?
Why do we use static methods in c#?
What are custom exceptions? Why do we need them?
Howmany five tracing levels in System.Diagnostics.TraceSwitcher? Why they are using?
Who introduced c#?
Is int an object in c#?
What is the difference between wrapper class and primitive?
What is a console device?
What is the use of getcommandlineargs() method in c#.net?
What is an assembly in .net?
What are generics in c#.net?
Which is better python or c#?
Why do we use 0?
How to Show Message box in Metro Style App?