+ 1
How do I create my own exception?
handling exceptions
3 Answers
+ 6
You should be able to create a custom exception class that extends the Exception class, for example:
class WordContainsException extends Exception {
// Parameterless Constructor
public WordContainsException() {}
// Constructor that accepts a message public WordContainsException(String message) { super(message); } }
try { if(word.contains(" ")) {
throw new WordContainsException(); } } catch(WordContainsException ex) {
// Process message however you would like
}
https://www.webucator.com/how-to/how-create-an-exception-class-java.cfm
+ 1
thanks guys