Java gem of the day: throw exceptions from main()

jdavidb on 2008-02-11T15:04:48

So you're writing a quick main() method to test something (yes, I know you should be writing unit tests; I should, too), and the method you're testing throws exceptions. Don't write exception handling code. Let your calling environment (most likely the JVM) handle the exceptions: declare that your main() method just throws those exceptions. It won't make your main() method uncallable or unfindable by the JVM, and whatever your environment does in response will probably be at least as useful as whatever you would've written, such as printing a stack trace.