+ 1

If I want to create an exception class, what type of exception should I need to implement?

Checked or uncheched. What is the best pracetice?

19th Jul 2016, 11:20 AM
WPimpong
WPimpong - avatar
4 Respostas
+ 1
extend the Exception class. You can narrow down to specific exceptions such as RuntimeException which is particularly useful for logging for debugging purposes, also catching specific exceptions allows you to handle them specifically such as with a FileException you can handle the exception by making sure that you close your resource I.e. your file, in the industry checked is the best practice but it doesn't hurt to try to catch any unchecked exceptions that you might have not accounted for.
21st Jul 2016, 5:19 AM
Eric Gitangu
Eric Gitangu - avatar
+ 1
unchecked exception is the best practice
10th Aug 2016, 3:00 PM
srilekha
0
Some programmers will throw unchecked exceptions because they are too lazy to specify exceptions that can be recovered from. If you don't want to be this lazy programmer who doesn't bother to do it right, then use checked exceptions where it is applicable. Meaning if you or whoever uses your code can handle the exception and recover from it, make it checked else if they cannot recover from it, make it unchecked.
19th Jul 2016, 1:47 PM
Gershon Fosu
Gershon Fosu - avatar
- 2
Incorrect questions
24th Jul 2016, 7:59 AM
Akash Kumar
Akash Kumar - avatar