Image

Imagewonkyear wrote in Imagejava_dev

newb question: custom exceptions

Hey there. I'm doing a project in Java for one of my comp sci classes, and one of the requirements is to throw and handle a custom exception. I could do this with a predefined exception, but I'm not sure how to define my own. Could anyone give a quick example of syntax/usage for custom exceptions?

I know I could find this on my own, but I'm posting the question here in hopes of saving research time.

If it affects the answer, the exception is to be thrown if the user attempts to insert a duplicate integer into a binary search tree object. In my implementation, the tree class will throw the exception, and the main method will handle it.

Thanks in advance for any help.