What is the correct syntax of the try-catch block?

Việt Quân

New member
What is the correct syntax of the try-catch block?
A.
try
{
// programable codes.....
}
catch(Exceptions)
{
// Code for handling exceptions....
}
B.
try()
{
// programable codes.....
}
catch(Exceptions)
{
// Code for handling exceptions....
}
C.
try
{
// programable codes.....
}
catch
{
// Code for handling exceptions....
}
D.
try()
{
// programable codes.....
}
catch
{
// Code for handling exceptions....
}
 
Answer: a
Explanation: Try-catch block has the following syntax:
Code:
try{
	// codes that needs to check for exceptions
}
catch(Exception E1){
      // codes for handling exception.... 
      // Exception E denotes the type of exception this block is handling.
}
catch(Exception E2){
	// other exception that needs to be handled...
}
You can have any number of catch blocks catching different exceptions…..
 

Tìm kiếm

Back
Top