Header Ads

Header ADS

example:3:exception

 class CustomException extends Exception {

    public CustomException(String message) {
        super(message);
    }
}

// Main program
public class firstprogramm {
    public static void main(String[] args) {
        try {
            int value = 11;
           
            if (value < 10) {
                throw new CustomException("Value is too small!");
            }
           
            System.out.println("there is no exception.");
        } catch (CustomException e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }
}
this is image


No comments

Powered by Blogger.