FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Java Fundamentals

CSE

Progress0 / 6 lessons
  1. 1. JVM, JDK and JRE explained properly
  2. 2. Classes, objects and the main method
  3. 3. Primitives, objects and autoboxing
  4. 4. String immutability and why == fails
  5. 5. Collections: ArrayList and HashMap
  6. 6. Exceptions and try-with-resources

Courses › Java Fundamentals

Exceptions and try-with-resources

Checked vs unchecked, what finally guarantees, and closing files correctly.

12 min read · Lesson 6 of 6 · Pro

An exception is a return path for failure

In C, a function that fails returns -1 or NULL and the caller is trusted to check. Nobody checks every time, so failures get ignored and surface later as corrupted data.

Java takes the other route. When something goes wrong, the method throws an exception: normal execution stops, and the JVM walks back up the call stack looking for a handler. Nothing can be silently ignored.

Java
public class Basic {
    public static void main(String[] args) {
        int[] a = {1, 2, 3};
The rest of this lesson is Pro

The free lessons of Java Fundamentals finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.