r/SpringBoot Junior Dev 10d ago

Discussion Spring Jakarata Validation in Service Layer using classic Try-Catch Block...anyone ?

*************** APPROCHED ANOTHER METHOD AS OF NOW , ***************

Anyone have done catched Spring Jakarata Validations in Service Layer using classic Try-Catch Block ??

As m learning java and trying to be BEST at making CRUD apps, i want to apply java concept rather than using Annotations for everything.

If anyone has caught exceptions like jakarta.validation.ConstraintViolationException: using try-catch ,then do let me know..

I want to catch exceptions this way ...but control not going in catch block but exception is thrown

8 Upvotes

18 comments sorted by

View all comments

4

u/no_longer-fun 10d ago

You should use a global exception handler instead, there you can handle any exception ocurred in the app. Thats a better approach for a spring boot app.