Types of Errors

Things To Do First

Things To Do Later

Types of Errors

At this point, errors are nothing new to you as a programmer. This is not necessarily a bad thing, since you learn a lot by debugging a program and fixing errors. In order to understand what Exceptions are, you need to understand the different kinds of errors that can occur in a program and how we go about solving each one.

There are three categories of errors in programming (these are covered in Chapter 1.10 of your textbook):

Compile-time Errors

(or just "Compile/Compilation Errors")

Examples of Compilation Errors

Run-time Errors

(or "Execution Errors")

Examples of Run-Time Errors:

Logic Errors

Examples of Logic Errors:

Note
Stylistic errors and mistakes or omissions in adhering to programming standards are not considered in any of the above categories.

Exercise

For each of the following programs below:
a. Identify any errors in the program.
b. Indicate the category of each error (Compilation Error, Run-Time error, or Logic Error)

  1. Example A:
    public class SomeErrors {
    
        public void main(String[] args) {
    
            System.out.print("Hi");
            System.out.printlm("Hello");
            System.out.print("Bye" \n);
        }
    }
  2. Example B:
    public class SomeErrors {
    
        public static void main(String[] args) {
    
            int number;
            int value = 1;
            number++;
            double result = number / value;
            System.out.println("Result: " result);
        }
    }
  3. Example C:
    public class SomeErrors {
    
        public static void main(String[] args) {
    
            Scanner in = new Scanner();
            System.out.println("Enter number of cats.");
            number = in.nextInt();
            System.out.printf("%4.2f is too many cats.", number);
        }
    }

[solutions]