- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between checked and unchecked exceptions in Java?
A checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation; the programmer should take care of (handle) these exceptions.
Example
If you use FileReader class in your program to read data from a file, if the file specified in its constructor doesn't exist, then a FileNotFoundException occurs, and the compiler prompts the programmer to handle the exception.
import java.io.File; import java.io.FileReader; public class FilenotFound_Demo { public static void main(String args[]) { File file = new File("E://file.txt"); FileReader fr = new FileReader(file); } }
Output
C:\>javac FilenotFound_Demo.java FilenotFound_Demo.java:8: error: unreported exception FileNotFoundException; must be caught or declared to be thrown FileReader fr = new FileReader(file); ^ 1 error
- Related Articles
- Checked vs Unchecked exceptions in Java
- Checked Vs unchecked exceptions in Java programming.
- Difference Between Checked and Unchecked Exception in Java
- Checked vs Unchecked Exceptions in C#
- Are the instances of Exception checked or unchecked exceptions in java?
- What are unchecked exceptions in Java?
- What are checked exceptions in Java?
- While chaining, can we throw unchecked exception from a checked exception in java?
- How can we decide that custom exception should be checked or unchecked in java?
- What is the difference between Java and Core Java?
- What is the difference between Java and Java EE
- What is the difference between >> and >>> operators in Java?
- What is the difference between /* */ and /** */ comments in Java?
- What is the difference between Java and JavaScript?
- What is the base class for errors and exceptions in Java?

Advertisements