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

Define constructors

550


What is difference between ilist and list?

483


What is parsing? How to parse a date time string?

534


How do you create dlls in .NET

570


Why are strings immutable in c#?

490






What is an int in c#?

521


What is enumerable in c#?

472


Is null in c#?

481


What is dao in c#?

488


How do you prevent a class from being inherited?

527


What is action in c# 3.5?

534


Explain About multi level and multiple inheritance how to achieve in .net

571


What are sorted lists?

500


What are some examples of desktop applications?

498


Explain the difference between “system.array.clone()” and “system.array.copyto()” in c#?

508