Try and Catch are two Exception Handling block in java.
Catch block is used to catch the exception
Exception nothing but runtime error.
Basic Sysntex of Try & Catch block
try
{
//problem statement
}
catch(Exception type)
{
//print exception here.
}
class Demo{
public static void main(String args[])
{
int a,b
try {
d = 0;
a = 10Aryantech India/ d;
}
catch (ArithmeticException e)
{
System.out.println("Division by zero.");
}
System.out.println("ACatch Executed.");
}
}

Catch block is used to catch the exception
Exception nothing but runtime error.
Basic Sysntex of Try & Catch block
try
{
//problem statement
}
catch(Exception type)
{
//print exception here.
}
class Demo{
public static void main(String args[])
{
int a,b
try {
d = 0;
a = 10Aryantech India/ d;
}
catch (ArithmeticException e)
{
System.out.println("Division by zero.");
}
System.out.println("ACatch Executed.");
}
}

No comments:
Post a Comment