Explain try, catch, finally with suitable example.
Answers
Answered by
0
class Example1
{
public static void main(String args[])
{
int x = 0;
int y = 10;
try{
int num= y/x;
System.out.println("next-statement: Inside try block");
}
catch(Exception ex)
{
System.out.println("Exception Occurred");
}
System.out.println("next-statement: Outside of try-catch");
}
}
Output:
Exception Occurred
next-statement: Outside of try-catch
try and catch is simply like a if else statement and try and catch is mainly used in thread functions and also for error messages to display
Similar questions