Im trying to find a quick way to catch all of my programs errors. These
would be the last remaining errors that are not currently caught in my
application,
for instance it would be a nullpointer exception - one that I never
expected to occur, so it was not caught. What I would like to do is to
catch any and all exceptions and log them in some way so that I can
update the program, and alert the user to the fact that an error had
occurred. The later I get, the catching all uncaught errors I am lost
with.
Any advice?
Thanks
re-point the con out to you logger., (do it VERY early in your code)
public class consoleIntercept extends PrintStream {
private PrintStream console = System.out;
private PrintStream err = System.err;
public consoleIntercept() {
super(System.out, true); // Autoflush
System.setOut(this);
System.setErr(this);
}
public void dispose() {
System.setOut(console);
System.setErr(err);
}
public void println(Object x) {
Error_stuff.handleError(x.toString());
}
}
I have 2 error systems , one that traps and dumps inside try{}catch{}
blocks, and then the above "catch all"
an example is below (where stuff is being written to the console , that
should not be, but obviously it catches dumps as well)
2006-05-23 07:25:34,353 ERROR com.Errors - INTERCEPT----dispatch watcher
expired
2006-05-23 07:37:31,634 ERROR com.Errors - INTERCEPT----dispatch watcher
expired
2006-05-23 07:42:04,457 ERROR com.Errors -
INTERCEPT----[Ljava.lang.Object;@a7166f
2006-05-23 07:54:09,947 ERROR com.Errors - INTERCEPT----dispatch watcher
expired
2006-05-23 07:59:42,787 ERROR com.Errors -
INTERCEPT----com.RecordStructures.SupplierRecordStructure@f45223
2006-05-23 17:36:38,483 ERROR com.Errors - INTERCEPT----dispatch watcher
expired
2006-05-23 17:37:10,108 ERROR com.Errors - INTERCEPT----dispatch watcher
expired
and now a "dump" of a missing class
2006-05-19 18:23:07,885 ERROR com.Errors - INTERCEPT----Exception Caused when
trying to Execute main Class
2006-05-19 18:23:07,896 ERROR com.Errors -
INTERCEPT----java.lang.reflect.InvocationTargetException
2006-05-19 18:23:07,898 ERROR com.Errors - INTERCEPT---- at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2006-05-19 18:23:07,898 ERROR com.Errors - INTERCEPT---- at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2006-05-19 18:23:07,898 ERROR com.Errors - INTERCEPT---- at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.j
ava:25)
2006-05-19 18:23:07,899 ERROR com.Errors - INTERCEPT---- at
java.lang.reflect.Method.invoke(Method.java:324)
2006-05-19 18:23:07,899 ERROR com.Errors - INTERCEPT---- at
bootLoader.bootLoader$3.run(bootLoader.java:199)
2006-05-19 18:23:07,899 ERROR com.Errors - INTERCEPT---- at
java.lang.Thread.run(Thread.java:552)
2006-05-19 18:23:07,900 ERROR com.Errors - INTERCEPT----Caused by:
java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleDataSource
2006-05-19 18:23:07,900 ERROR com.Errors - INTERCEPT---- at
com.sql.SQL_stuff.Open_odbc(SQL_stuff.java:2364)
2006-05-19 18:23:07,900 ERROR com.Errors - INTERCEPT---- at
RootClassFrame.RootClassFrame.main(RootClassFrame.java:376)
2006-05-19 18:23:07,900 ERROR com.Errors - INTERCEPT---- ... 6 more
2006-05-19 18:55:25,997 ERROR com.Errors - INTERCEPT----dispatch watcher
expired