how can i trap nested exceptions
1 posts in topic
Flat View  Flat View

Posted By:   Mahendra_Goyal
Posted On:   Thursday, May 31, 2001 10:01 PM

how can i trap the nested exceptions while sending mail for example Transport.sendMessage(..) throws MessagingException where often the nested exception is IOException or FileNotFoundException because i am using attacment so if the file path is incorrect this exception is thrown.I would like to catch the precise exception but because the exception thrown is MessagingException only its subclasses can be caught.Currently i am using something like if(ex.getMessage().indexOf("IOException")>=0){do something....} to trap a IOException while attaching to the mail.Is it reliable or there is a better way to do this.

Re: how can i trap nested exceptions

Posted By:   John_Zukowski  
Posted On:   Thursday, May 31, 2001 10:33 PM

As you state, you can only catch the thrown exception. The 1.4 API adds the ability to chain exceptions so you can find out the 'cause'.

A better way is to make sure your filepath is present/correct before trying to use it with an attachment.

About | Sitemap | Contact