?
Solved

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

Posted on 2005-04-01
10
Medium Priority
?
257 Views
Last Modified: 2010-03-31
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 :)
0
Comment
Question by:yeggstry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13680534
Will e.getMessage() work?

What do you mena by root cause exactly?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13680538
or e.getCause() ;
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13680545
No, getCause() is 1.4 isn't it...
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 80 total points
ID: 13680572
e.printStackTrace()
0
 

Author Comment

by:yeggstry
ID: 13680582
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
 

Author Comment

by:yeggstry
ID: 13680588
I also need just the cause message, not the whole stacktrace (the error is being displayed on the screen for the user).
0
 
LVL 29

Assisted Solution

by:bloodredsun
bloodredsun earned 80 total points
ID: 13680681
I think that CEHJ is right and you'll have to use  e.printStackTrace() and parse out the answer yourself.
0
 

Author Comment

by:yeggstry
ID: 13680777
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
 
LVL 15

Accepted Solution

by:
aozarov earned 340 total points
ID: 13681122
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
 

Author Comment

by:yeggstry
ID: 13681175
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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question