Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Class untuk penanganan error dengan throw keyword
- *
- * @author Ahmad Lamaul Farid
- * @version 24 Desember 2020
- */
- public class Main
- {
- static void checkAge(int age)
- {
- if (age < 18)
- {
- throw new ArithmeticException("Access denied - You must be at least 18 years old.");
- }
- else
- {
- System.out.println("Access granted - You are old enough!");
- }
- }
- public static void main(String[] args)
- {
- checkAge(15); // Set age to 15 (which is below 18...)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement