Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+18 votes
asked in CSC305 Fall 2022 by (1 point)

2 Answers

+10 votes

checked exception occur at compile time where as unchecked exception occur at runtime.

answered by (1.1k points)
+9 votes

Checked exception
- Checked exceptions occur at compile time.
- The compiler checks a checked exception.
- These types of exceptions can be handled at the time of compilation.
Example - File Not Found Exception, No Such Field Exception

unchecked exception
- Unchecked exceptions occur at runtime.
- The compiler does not check these types of exceptions.
- These types of exceptions cannot be a catch or handled at the time of compilation because they get generated by the mistakes in the program.
Example - Empty stack exception, Arithmetic exception, null pointer exception.

answered by (1 point)

This seems generally right, except that both kinds can be caught with a try/catch block.

A key difference is that "checked exceptions" must be handled (with try/catch, or by a "throws" declaration) or the compiler won't let your code compile.

It is up to you whether or not to handle any "unchecked" exceptions in your code.