3

In domain model of my web application I've an entity Foo which can be created only by a pojo FooBean: Foo.newInstance(FooBean fooBean) (Might have been better a Builder-pattern.)

In the factory methode newInstance() the pojo FooBean is validated and throws NullPointerExceptions and IllegalArgumentExceptions if needed. The fields of the pojo are filled by a form on the presentation layer. That form does some validation on the user input and shows user friendly messages if needed.

The exception message of the NullPointerExceptions and IllegalArgumentExceptions thrown in the newInstance() method are rather technical and shouldn't be displayed to the end user.

What is a proper way to show user friendly error messages that are originated by the NullPointerException or the IllegalArgumentException?

3

Be specific, throw early, and catch late.

I think you are missing both the "be specific" as well as the "catch" parts.

You should be throwing descriptive exceptions and handling them as appropriate, where appropriate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.