kcpr
kcpr

Reputation: 1105

Is it possible to catch 'Execution exception' in Java Play Framework?

I would like to somehow catch the 'Execution exception' which is normally shown in browser. I just don't like the fact that I have to validate data manually, when they seem to be validated by Play anyway.
For example I would like to catch exceptions like the one below.

[IllegalStateException: Error(s) binding form: {"email":["Valid email required"]}]

It appears after User user = Form.form(User.class).bindFromRequest().get(); in my example.

Upvotes: 1

Views: 794

Answers (1)

Mon Calamari
Mon Calamari

Reputation: 4463

IllegalStateException is a runtime exception and is not meant to be caught. Replace your code with:

Form<User> userForm = Form.form(User.class).bindFromRequest();
if(userForm.hasErrors()) {
    return badRequest();
} else {
    User user = userForm.get();
    // whatever
    return ok();
}

Upvotes: 1

Related Questions