Day 16 - 11 Oct - Exception handling end
Throwing Exceptions
public class CustomExceptionExample {
public static void main(String[] args) {
try {
throw new CustomException("This is a custom exception.");
}
catch (CustomException e) {
System.out.println("Caught custom exception: " + e.getMessage());
}
}
}
class CustomException extends Exception {
public CustomException(String message) {
super(message);
}
}Using throws Keyword Example
throws Keyword ExampleLast updated