Professional Documents
Culture Documents
Practical No. 26 & 27
Practical No. 26 & 27
26 & 27
Program Code: Program using ‘throw’ and ‘throws’ clause
class Main {
try {
check ();
} catch (ArithmeticException e) {
}}}
throw new ArithmeticException ("Access Denied - You must be atleast 18 years old");
} else {
}}
checkAge (15);
}}
Exercise:
1) Define an exception called "NotMatchException" that is thrown when a string is not equal
to "India". Write a program that uses this exception
import java.lang.Exception;
import java.util.*;
public NotMatchException () {
}}
class India {
String Str;
try {
Str=S.next();
if (!Str.equals("India")) {
else {
catch (NotMatchException e) {
System.out.println(e);
}}}
2) Write the output of the following program:
class tst1{
Thread.sleep(10000);
System.out.println("Hello Java");
}}
Thread.sleep(10000);
System.out.println("Hello Java");
}}