Tutorials     About     RSS
Tech and Media Labs

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

Thread Congestion in Java - Video Tutorial

Sponsored Ads

Maildroppa - Smart Email Marketing Solution
Close TOC

All Trails

Trail TOC

Page TOC