How to create custom error messages in APEX?
In Apex specifically, use validations. You can specify them per field or use a custom one that checks all the fields at once.

http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/bldr_validate.htm#BABCDBDE