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

Can you see a loop recorder?

657


What are the characteristics of c#?

672


What is the use of delegate?

724


What do you mean by saying a "struct is a value type"?

690


Why do I get a security exception when I try to run my c# app?

763


What is dll file in c#?

722


What are jagged arrays used for?

680


What is a nested type. Give an example?

826


Explain About Iunknown interface Queue

722


Can we inherit static class in c#?

685


What are modifiers in c#?

645


Can extension methods access private members?

672


Explain the difference between const and static read-only?

708


What is default value of decimal c#?

653


What does firstordefault mean in c#?

714