Please see my custom exception file (ExceptionHandler.java) below:
package utilities;
public class ExceptionHandler {
public void browserException() throws BrowserException {
new BrowserException();
}
public void userInputException() throws UserInputException {
new UserInputException();
}
public void timeOutException() throws TimeOutException {
new TimeOutException();
}
public void notFoundException() throws NotFoundException {
new NotFoundException();
}
}
//////////////////// Exception List Here ////////////////////
@SuppressWarnings("serial")
class BrowserException extends Exception {
public BrowserException() {
System.out.println("Unhandled Browser!");
}
}
@SuppressWarnings("serial")
class UserInputException extends Exception {
public UserInputException() {
System.out.println("Invalid user-input!");
}
}
@SuppressWarnings("serial")
class TimeOutException extends Exception {
public TimeOutException() {
System.out.println("Script timed out!");
}
}
@SuppressWarnings("serial")
class NotFoundException extends Exception {
public NotFoundException() {
System.out.println("Element Not Found!");
}
}
I'm trying to call this ExceptionHandler-class as shown-below, but getting errors like "No exception of type void can be thrown; an exception type must be a subclass of Throwable".
throw new ExceptionHandler().browserException();
Kindly anyone let me know, if at all it is a valid way. If not, then what all could be the best possible approaches to group multiple custom-exception classes? Please bear with me as I'm a novice in Exception Handling.
Many thanks!