https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html
why uses Unchecked Exceptions ?
Runtime exceptions represent problems that are the result of a programming problem, and as such, the API client code cannot reasonably be expected to recover from them or to handle them in any way. Such problems include arithmetic exceptions, such as dividing by zero; pointer exceptions, such as trying to access an object through a null reference; and indexing exceptions, such as attempting to access an array element through an index that is too large or too small.
Runtime exception can not be predicted, so it is not expected to get recovered.
why uses Checked Exceptions ?
Can be predicted, eg open a file: FileNotFoundException
So we need to catch it during compiling: use try catch block or through an exception in the method.
No comments:
Post a Comment