• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

Java Exceptions

Contents

  • When to use Errors and Exceptions
  • How to throw an exception
  • Common Exceptions
  • See also
This is a quick article I had for quite a while as a draft. It might not be finished or have other problems, but I still want to share it.

When to use Errors and Exceptions

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.

(Source: Javadoc)

How to throw an exception

public void myMethod( String s ) {
  if (!isStringValid(s)) {
    throw new IllegalArgumentException("This string is not valid!");
  }
}

Common Exceptions

  • IllegalArgumentException: One argument of the current method hasn't the form it should have.
  • IllegalStateException: The current object is in the wrong state.
  • NullPointerException: A Null-Pointer was given, but it should have been an object.

A long list of Exceptions is on Hai's Blog.

See also

  • http://docs.oracle.com/:
    • Class Exception

Published

Dez 29, 2014
by Martin Thoma

Category

Code

Tags

  • Exception 1
  • Java 36

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor