Checked exception with constructor

Report a typo

Write a program that creates a checked exception named CustomException and has a constructor with an Exception argument.

Sample Input 1:

smth went wrong

Sample Output 1:

java.lang.Exception: smth went wrong
Write 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..
___

Create a free account to access the full topic