What are checked and unchecked exceptions in Java?

Quality Thought is a leading Full Stack Java Institute in Hyderabad, offering comprehensive training and a live internship program designed to equip students with the practical skills needed to excel in the software development industry. Our expert instructors provide hands-on training in both front-end and back-end technologies, ensuring that participants gain a well-rounded understanding of the Full Stack Java ecosystem.

Our live internship program allows students to work on real-world projects, giving them valuable industry experience and the opportunity to apply what they've learned in a professional setting. This unique learning model bridges the gap between theoretical knowledge and practical application, helping students build a strong portfolio to showcase to potential employers.

As a top-rated Full Stack Java Institute in HyderabadQuality Thought focuses on providing personalized training sessions, ensuring that every student receives the attention and support needed to succeed. Our course covers core Java, Spring Boot, Angular, React, database management, and more.

In Java, exceptions are categorized into checked and unchecked exceptions, based on how the compiler enforces exception handling.

Checked Exceptions:

These are exceptions that the compiler checks at compile-time. If a method throws a checked exception, it must either handle it with a try-catch block or declare it using the throws keyword.

  • Examples: IOException, SQLException, FileNotFoundException

  • Use case: Situations that are outside the program’s control, like reading a file or accessing a database.

If not handled or declared, the code won’t compile.

⚠️ Unchecked Exceptions:

These are not checked at compile-time. They occur at runtime and typically represent programming errors, such as logic bugs or improper use of an API.

  • Examples: Null Pointer Exception, Array Index Out Of Bounds Exception, Arithmetic Exception

  • Use case: Errors that should be fixed in code and not usually recovered from during execution.

Unchecked exceptions extend Run time Exception, while checked exceptions extend Exception (but not Run time Exception).

Summary:

  • Checked = must handle/declare; used for recoverable conditions.

  • Unchecked = optional handling; used for programming errors.

Read More

What is the Java Virtual Machine (JVM)?

Visit QUALITY THOUGHT Training institute in Hyderabad

Comments

Popular posts from this blog

What is the default value of an uninitialized int variable in a Java class?

What is the difference between == and .equals() in Java?

What is the role of RESTful APIs in Full Stack Java development?