ryandlf
ryandlf

Reputation: 28545

Catching Javamail Exceptions

I am planning on using javamail to sent automated emails in a loop type fashion. So for example I might have 300 emails that I need to build and send out with javamail one after the other. I am using timers in java to automate the process at a specific time each day.

What exceptions should I attempt to catch and how do I handle the error when I do catch an exception without interrupting the loop? What exceptions should I expect to run into? Unable to connect to SMTP server? Invalid email address? Etc?

Upvotes: 1

Views: 2346

Answers (1)

duffymo
duffymo

Reputation: 308753

You'll have to put the try/catch inside the loop. If you want the loop to keep going, you should just log the exception and process the next attempt.

As for which exceptions to catch, you'll be forced to catch all the checked ones. If you don't want unchecked exceptions to interrupt the processing you'll have to catch those, too. I would not go so far as to catch Throwable.

Upvotes: 2

Related Questions