dgl viru
dgl viru

Reputation: 177

Customized Exception is checked or unchecked Exception?

Whether the Customized Exception is Checked or Unchecked Exception? How?

Upvotes: 1

Views: 181

Answers (4)

Manish Prajapati
Manish Prajapati

Reputation: 392

depends on inheritance. if it inherits from RuntimeException it is unchecked. Otherwise it is checked

Upvotes: 0

Razib
Razib

Reputation: 11173

It depends on what it inherits. If your custom exception is a subclass of RuntimeException then it is unchecked exception.

And if your custom exception extends Exception class then it is checked exception.

See the Differences between Runtime/Checked/Unchecked/Error/Exception for more details

Upvotes: 0

Garry
Garry

Reputation: 4533

If you do like this:

public class CustomException extends Exception

then your CustomException is checked exception

If you do like this:

public class CustomException extends RuntimeException

then your CustomException is unchecked exception

Upvotes: 2

khelwood
khelwood

Reputation: 59203

If an exception inherits from RuntimeException then it is unchecked. Otherwise it is checked.

Upvotes: 0

Related Questions