When we have System defined exception classes in Java, then why there is need to make user defined exception classes? Because my teacher told me to make Exception classes in
There are a few reasons to have user defined exceptions:
ConstraintViolationException. You know immediately that you have a problem with some kind of constraint on the database (probably foreign key constraint). Having said that, in general you should prefer to use the built in Exceptions or at least have your custom Exceptions extend the built-ins so users don't have to care about your special classes unless they want to.
For more info about why you should prefer the built-in exceptions see Effective Java Item 60: Favor the use of standard exceptions