• Courses
  • Tutorials
  • Practice
Switch to Dark Mode

Which of the following correctly defines a custom exception?

Last Updated : Apr 3, 2025
Discuss
Comments

Which of the following correctly defines a custom exception?

A
Java
class MyException {
    public MyException(String message) {
        super(message);
    }
}


B
Java
class MyException extends RuntimeException {
    public MyException(String message) {
        super(message);
    }
}


C
Java
class MyException extends Throwable {
    public MyException(String message) {
        super(message);
    }
}


D
Java
class MyException extends Error {
    public MyException(String message) {
        super(message);
    }
}


Share your thoughts in the comments