Exception Handling · Introduction to Java Programming

Errors in Java Programs

Watch lectures

Errors in Java Programs

1. Three Kinds (beginner — which can you catch?)

Compile-time (javac stops you: ; missing!), Runtime (JVM crashes: divide by zero!), Logical (runs, wrong answer: average bug!). Only runtime exceptions catchable!

2. Table + Examples (exam!)

// int x = 5  // COMPILE (missing ; — red underline, no .class!)
// int y = 10 / 0; // RUNTIME (ArithmeticException — crashes!)
int total = 7, n = 2;
System.out.println(total / n); // 3 (LOGICAL — runs, wrong average! need /2.0!)
Kind When Fix
Compile (syntax/type) javac time read error line, fix ;/types
Runtime (exception) java run time try-catch (next topics!)
Logical runs, wrong output test + debug (print values!)

3. Error vs Exception (Java words!)

Error (fatal: OutOfMemory, StackOverflow — don't catch!) vs Exception (catchable: Arithmetic, NullPointer, ArrayIndex!).

4. Beginner Workflow

Red in IDE? Compile error (fix first!). Crash with name+line? Runtime (read stack trace bottom→top for YOUR line!). Wrong number? Logical (add prints!).

5. Exam Points

  • Three kinds + example each — 5 marks, very frequent.
  • Error vs Exception — 3 marks, frequent.
Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.

← All Introduction to Java Programming modules