+ 1

How do I create my own exception?

handling exceptions

21st Dec 2017, 9:30 AM
Jamiu Akinyemi
Jamiu Akinyemi - avatar
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
21st Dec 2017, 9:39 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
thanks guys
21st Dec 2017, 9:43 AM
Jamiu Akinyemi
Jamiu Akinyemi - avatar