Skip navigation

Exceptions in Java are divided into two groups; checked and unchecked (or runtime) exceptions.

Checked exceptions will extend java.lang.Exception and must be declared in the method signature if thrown.

Runtime exceptions do not need to be declared by throwing methods and either extend java.lang.RuntimeException or java.lang.Error.

Checked exceptions tend to be exceptions you can reasonably be expected to do something about and recover whereas runtime exceptions should be those which cannot be recovered from.

If you’re writing an application dependent upon a database and the database connection can’t be established then that’s likely to be terminal. This should be a runtime exception – it’s ok to blow up over this.

If a single transaction fails then you might expect a checked exception to be thrown, to rollback the transaction and allow program execution to continue.

Advertisement

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.