Can I get the cause of an exception using Java 1.3.1?

Simple enough question, but is it possible :/ I Must use 1.3.1 for compatibility with other products (i.e. websphere) but I'm not sure if this is possible. If I need another class to do it then that's fine.

Thanks in advance for your help :)
yeggstryAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aozarovConnect With a Mentor Commented:
Have a look at http://www.docjar.org/html/api/org/apache/log4j/spi/LocationInfo.java.html
This is the source code for LocationInfo which is used by log4j determine which class / method / line was throwing the exception. (to be compatible with 1.3
that doesn't have the getStackTrace method (since 1.4). you can use similar logic to pick the line you code that you have interest in.
0
 
bloodredsunCommented:
Will e.getMessage() work?

What do you mena by root cause exactly?
0
 
bloodredsunCommented:
or e.getCause() ;
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
bloodredsunCommented:
No, getCause() is 1.4 isn't it...
0
 
CEHJConnect With a Mentor Commented:
e.printStackTrace()
0
 
yeggstryAuthor Commented:
OK, in the system I am using it throws an error where the e.getMessage() is:

Unable to connect: com.ncode.gdm.command.NCCommandException: Error running process.

BUT there are two possible causes for this message to be thrown....

Could not get the path of the filestore root directory.

or

Unable to find process(core22_GetSystemParameters)

at the moment I am using e.getCause() to get it, but that is not 1.3.1 compatible :/

Any ideas?
0
 
yeggstryAuthor Commented:
I also need just the cause message, not the whole stacktrace (the error is being displayed on the screen for the user).
0
 
bloodredsunConnect With a Mentor Commented:
I think that CEHJ is right and you'll have to use  e.printStackTrace() and parse out the answer yourself.
0
 
yeggstryAuthor Commented:
dammit that sucks :/ ok, so how would I manipulate the stack trace to get the cause? Could I use regular expressions and if so how could I get the stackTrace into something I can work with?
0
 
yeggstryAuthor Commented:
Yup, that's great :) thanks

I've managed to compress it down to what I need, at its simplist form you can do:

            StringWriter sw = new StringWriter();
            ex.printStackTrace(new PrintWriter(sw));
            String stacktrace = sw.toString();
            System.out.println("stacktrace = " + stacktrace);

which is exactly what I need to do my regular expressions :)

Thanks for your help guys.
0
All Courses

From novice to tech pro — start learning today.