Advertisement
zoro-10

Pr3b.java

Mar 30th, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. class CustomException extends Exception {
  2.  
  3.   public CustomException(String message) {
  4.     super(message);
  5.   }
  6. }
  7.  
  8. public class Pr3b {
  9.  
  10.   public static void main(String args[]) {
  11.     try {
  12.       int age = -20;
  13.       if (age < 0) {
  14.         throw new CustomException("Age can't be negtive.");
  15.       }
  16.       System.out.println("Aeg:" + age);
  17.     } catch (CustomException e) {
  18.       System.err.println("Error:" + e.getMessage());
  19.     }
  20.   }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement