2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

04/21/2004: Catching Java Errors in the main() Method.

I've been using Java for more years than I care to mention but I never realized that you could catch errors as well as exceptions.i So I've just added one more item to my toolbox. My main() method always uses this template:
try {
  // do something.
} catch (Error e) {
  e.printStackTrace();
} catch (Exception e) {
  e.printStrackTrace();
} finally {
  System.out.println("Done.");
}

Of course, in my real code I use log4j so that the errors are persisted.



subscribe via RSS