rdonuk
rdonuk

Reputation: 3956

Collecting all uncaught exceptions in a big application

I have server-client application which has a several users. My client is a big application and there is a lot of exception handlings inside of it. I want to collect and transfer all uncaught exceptions whichs are unhandling. For example, when a client throw an uncaught exception like NullPointer or ArrayIndexOutOfBounds exception, i want to transfer the message to the server and write it to a file. Is it possible?

Upvotes: 0

Views: 115

Answers (3)

trashgod
trashgod

Reputation: 205885

Any advice for logging?

As shown here and here, you can add a default uncaught exception handler. As shown here, you can display the stack trace in a dialog.

Upvotes: 1

Sunny
Sunny

Reputation: 308

If you want to print the entire stack trace, use printStackTrace:

FileWriter fw = new FileWriter("exception.txt", true);
PrintWriter pw = new PrintWriter(fw);
e.printStackTrace (pw);

Upvotes: 0

Sanjeev
Sanjeev

Reputation: 9946

Yes, It is possible but not advisable. As Swing works on a Single Threaded Model, all the events are handled by EDT so for a possible solution you need to capture these exceptions at the place from where these events are dispatched.

EventQueue is the place that keeps track of all the events, so you can override it in your application (NOT A GOOD IDEA) and catch all the exceptions there and send to server from there in a separate thread.

And also you need to capture exceptions in all the threads your application is creating (other than swing threads).

More appropriate solution would be to log them at client side only and these log file can later be scanned to check for the exceptions.

Hope this helps.

Upvotes: 0

Related Questions