aspose file tools*
The moose likes Java in General and the fly likes how to select root cause of exception from nested exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to select root cause of exception from nested exception " Watch "how to select root cause of exception from nested exception " New topic
Author

how to select root cause of exception from nested exception

ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
hi all,

i am getting fileNotFound exception while attaching a file with message

java.sendMailException

-- nested exception java.io exception

-- nested exception java.io.fileNotFoundException

i want to select root cause of exception i.e. FileNotFoundException can you please tell me how to select that one

please reply

Thanks,
-Ravi
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Check out the API documentation for Throwable. You will find methods which will give you the cause.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
Thanks for reply,

but m still not getting solution.

i tried for getCause() and getRootCause() for that one but it is returning null

can you please explain in brief.

Thanks,
-Ravi.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

ravi pardeshi wrote:
but m still not getting solution.

Please use real words

Why don't you post your code so we can figure out what's going wrong
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Doesn't it appear in the stack trace?
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
Maneesh Godbole wrote:
ravi pardeshi wrote:
but m still not getting solution.

Please use real words

Why don't you post your code so we can figure out what's going wrong




if the attachment not exists then it is throwing exception



Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

I don't see any getCause() in your code.
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
get cause returning null in that method so i changed that one to getMessage()
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
If it returned null there probably was no cause to print.
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
then how come i will show exact problem to user ?
i.e. file not found at specific location
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23


output

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

ravi pardeshi wrote:then how come i will show exact problem to user ?
i.e. file not found at specific location

If getCause() returns null, then basically it means that, as far as the exception is concerned, it is the root cause. It may not be, but then the programmer forgot to set the cause and you can never retrieve it anymore.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3646
    
  15
This line

calls the toString() method on your ex object.
If you look at the source code for the org.springframework.mail.MailSendException class, you can see how toString gets its list of nexted exceptions and then do the same yourself.

Joanne
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
OK ...

thanks for response.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to select root cause of exception from nested exception