If the user makes an error in input, give the appropriate feedback, and allow them to correct the error if possible. It's very important to give specific feedback that allows them to correct their problem.
I recently used a program that produced "Error in processing" as the error message. There was no hint as to whether is was my error or a bug in the program. Grrrrr.
assert statements liberally to debug your own code.
Assertions are very easy to use and are very helpful during
testing, but have the disadvantage of being turned off by default
during execution. Try to run with them turned on if possible.
If you are writing code that is going to be used by others,
it is especially important to detect programmer errors and
throw an exception.
Exceptions - More,
altho quite incomplete, has an example using
IllegalArgumentException that might be useful.