Java User-defined exceptions:

Опубликовано: 14 Май 2026
на канале: Java code&Decode
97
8

User-defined exceptions: - These are the exceptions created by user of the language.
Creating user defined exceptions: -
a) Write user exception class as a sub class to exception class
Ex: - class MyException extends Exception
b) Write a default constructor in user exception class
Ex – MyException( ) { }
c) Write a string parameterized constructor & from their call the super class constructor.
Ex: - MyException(String str)
{
Super(str);
}
d) To raise the exception creates user exception class object & throw it using throw statement.
Ex: - throw me;