Error Detection

Jakob Jenkov
Last update: 2014-05-26

Error detection is what your code does to detect an error, preferrably before the error happens. For instance, you validate input parameters in a method, before using them. Here is a simple example:

public void doSomething(int value, Employee targetEmployee){

  if(value < 20) {
    throw new IllegalArgumentException("Value too low");
  }

  if(targetEmployee == null){
    throw new IllegalArgumentException("Target employee was null");
  }

  ... do actual work.
}

Notice the if-statements in the beginning of the method. These are error detecting statements. They check the input parameters for invalid values, and throw an exception if they are invalid.

The exception throwing itself in the example above is not part of the error detection. That is part of the "Throwing the exception", which I get into later. I have just shown them in the examples for clarity.

Jakob Jenkov

Featured Videos

Java Generics

Java ForkJoinPool

P2P Networks Introduction



















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next