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?


1 Answer 1


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.

  • 1
    Very useful article. Thank you. What would be nice to add to this article is the concept of Exception Translation.
    – Bart Weber
    May 15, 2014 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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