Java Exception

In java, exception structure  is like this :

                  /       |         \
                /         |           \
RunTimeException  SpecificException1   SpecificException2

Each class extends another one and the exception class extends throwable.

When you need to throw a custom exception, you need to create a customException which extends another Exception like RunTimeException, Exception or anotherCustomException.

public class ConflictException extends RuntimeException {

    public ConflictException() {

    public ConflictException(String message) {

    public ConflictException(String message, Throwable cause) {
        super(message, cause);

    public ConflictException(Throwable cause) {

    public ConflictException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);


The rule is to catch only exception when you want to add some information. Then you can throw it back like this :

catch (WhateverException e) {
    throw e;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s