Overriding (or something similar) Exceptions

G

graham.parsons

Hi guys,

We have a "legacy" Java application that has been developed by many
developers - some handle exceptions nicely, others not so.

What I would like to do is create a log of all the exceptions and
messages that are being thrown internally without changing the code.

I was thinking around the classloader - create my own Exception class
which uses the standard one but before passing the call to the standard
one, writes out to the log.

So mine is loaded by the JVM but all I do is extend the standard one
and override a method - is this "cyclic dependancy possible"?

If not, can anyone suggest any other route I could take to get the
desired functionality?

Cheers

Graham
 
O

Oliver Wong

Hi guys,

We have a "legacy" Java application that has been developed by many
developers - some handle exceptions nicely, others not so.

What I would like to do is create a log of all the exceptions and
messages that are being thrown internally without changing the code.

I was thinking around the classloader - create my own Exception class
which uses the standard one but before passing the call to the standard
one, writes out to the log.

So mine is loaded by the JVM but all I do is extend the standard one
and override a method - is this "cyclic dependancy possible"?

If not, can anyone suggest any other route I could take to get the
desired functionality?

Look into Aspect Oriented Programming, and AspectJ.

- Oliver
 
T

Tris Orendorff

Hi guys,

We have a "legacy" Java application that has been developed by many
developers - some handle exceptions nicely, others not so.

What I would like to do is create a log of all the exceptions and
messages that are being thrown internally without changing the code.

I was thinking around the classloader - create my own Exception class
which uses the standard one but before passing the call to the standard
one, writes out to the log.

So mine is loaded by the JVM but all I do is extend the standard one
and override a method - is this "cyclic dependancy possible"?

If I understand you, you can do this. Exceptions and classes are very
similar so you can say, "public class Mine extends IOException {}" and
write a new constructor. You still have to change the code to use your
new exceptions.

So my second suggestion would be to add the logging code to the runtime
library and whip up a special rt.jar file.

--
Sincerely,

Tris Orendorff
[Q: What kind of modem did Jimi Hendrix use?
A: A purple Hayes.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top