Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to capture java.lang.Error in log files

 
joe nesbitt
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a standalone java enviornment with robust exception handling and the application is well tested.

But some times the process flow is not behaving the way it is expected.
Thus I would want to keep track of anything abnormal that might be happening by looking at the log files. I am thinking that log4j configuration might not help me to log the occurence of the java.lang.Error subclasses.

Similar to the .out files in weblogic enviornment which logs everything that happens in the JVM including the occurence of any java.lang.Error (like stackoverflow/outofmemoryerror), is there a way to capture such errors when occured in a standalone/non-J2EE enviornment?

Any help is appreciated.

Thanks in advance for your time and input.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking that log4j configuration might not help me to log the occurence of the java.lang.Error subclasses.

Why ? log4j can log any java.lang.Throwable, java.lang.Error included.

is there a way to capture such errors when occured in a standalone/non-J2EE enviornment?

If you catch them at your program's entry point, yes. These are usually unrecoverable errors though, so even if you log the error, it might not be a good idea to continue as if nothing happened.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic