+ 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?
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.
+ 1
unchecked exception is the best practice
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.
- 2
Incorrect questions