Create a class named MyException, which must inherit from the base class for all exceptions and errors. Inside the MyException class declare a constructor that takes String message as an argument and passes the message to the superclass.
Hierarchy of exceptions
Base class
Report a typo
Write a program in Java 17
// update the class
class MyException extends ...{
}
//do not change the code
class Main {
public static void main(String[] args) {
MyException myException = new MyException("This is a custom exception");
System.out.println(myException.getMessage());
Class<?> superClass = myException.getClass().getSuperclass();
System.out.println(superClass.equals(Throwable.class));
}
}
___
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.