Write a program that creates a checked exception named CustomException and has a constructor with an Exception argument.
Custom exceptions
Checked exception with constructor
Report a typo
Sample Input 1:
smth went wrongSample Output 1:
java.lang.Exception: smth went wrongWrite a program in Java 17
import java.util.Scanner;
// Do not change the class
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Exception e = new Exception(sc.nextLine());
Exception customException = new CustomException(e);
System.out.println(customException.getMessage());
}
}
// Write a CustomException class that extends Exception
// and has a constructor with an Exception argument
class CustomException..
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.