| 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: 8441
|
|
|
Check out the API documentation for Throwable. You will find methods which will give you the cause.
|
[Donate a pint, save a life!] [How to ask questions] [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: 8441
|
|
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: 32712
|
|
|
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: 8441
|
|
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: 32712
|
|
|
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: 19216
|
|
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
How To Ask Questions How To Answer Questions
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
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.
|
 |
 |
|
|
subject: how to select root cause of exception from nested exception
|
|
|