Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to select root cause of exception from nested exception

 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the API documentation for Throwable. You will find methods which will give you the cause.
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50206
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't it appear in the stack trace?
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any getCause() in your code.
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
get cause returning null in that method so i changed that one to getMessage()
 
Campbell Ritchie
Sheriff
Pie
Posts: 50206
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it returned null there probably was no cause to print.
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then how come i will show exact problem to user ?
i.e. file not found at specific location
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


output

 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK ...

thanks for response.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic