AnyClassException
DRAFT

Misconception:

Any object of a class can be thrown as an exception.

Incorrect

Any class can be an exception class

Correct

Exceptions are subtypes of Throwable

Correction
Here is what's right.

Only instances of java.lang.Throwable and its subclasses can be thrown as exceptions.

try {
  throw new Throwable();
} catch (Throwable ex) {
  System.out.println(ex);
}

It’s not possible to throw values of other types (neither primitive nor reference). The following is illegal and will not compile:

try {
  throw "Oh My!";  // type error -- throw requires a Throwable
} catch (String ex) {
  System.out.println(ex);
}

Origin
Where could this misconception come from?

A reason for this Java misconception may be that a student already knows a language like JavaScript that allows throwing values of any type:

try {
  throw "Oh My!";  // ok in JavaScript
} catch (ex) {
  console.log("Caught " + ex);
}

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.