Create custom unchecked exception in Java

Create custom unchecked exception in Java –

You can create custom unchecked exception when you want to propagate certain exception handling responsibility to the caller method rather than handling it in place where exception is generated.

Unchecked java exception does not need to be caught or dealt with when using it in your application. It is used to indicate normal or acceptable error signal that can be ignored, For example, some validation related exception, logging related exception etc.

you can create unchecked exception by extending RuntimeException class. Below example explained how you can create unchecked exception and use it. The commented out statements you can use to catch or ignore as it is runtime exception.

OutPut:

custom-unchecked-exception

Gopal Das
Follow me

Gopal Das

Founder at GopalDas.Org
He is a technology evangelist, Salesforce trainer, blogger, and working as a Salesforce Technical Lead. After working in Java based project implementation, he jumped to the Salesforce system on a whim and never looked back. He fell in love with Salesforce’s flexibility, scalability, and power. He expanded his knowledge of the platform and became a Certified App Builder, Administrator, Platform Developer I, SalesCloud Consultant while leading the Salesforce implementation and technology needs. He has worked in a wide variety of applications/services like desktop, web and mobile applications.
Gopal Das
Follow me

Leave a Reply

Your email address will not be published. Required fields are marked *