Mail User Agent

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2007
Posts: 9
Reputation: krusso88 is an unknown quantity at this point 
Solved Threads: 0
krusso88 krusso88 is offline Offline
Newbie Poster

Mail User Agent

 
0
  #1
Nov 4th, 2009
For a computer networking course I was given a project to make a Mail User Agent. We were given a few completed classes, but one of them is giving an error. Here is the part of code in question:

  1. try {
  2. Envelope envelope = new Envelope(mailMessage,
  3. serverField.getText());
  4. } catch (UnknownHostException e) {
  5. /* If there is an error, do not go further */
  6. return;
  7. }
  8. try {
  9. SMTPConnection connection = new SMTPConnection(envelope);
  10. connection.send(envelope);
  11. connection.close();
  12. } catch (IOException error) {
  13. System.out.println("Sending failed: " + error);
  14. return;
  15. }
  16. System.out.println("Mail sent succesfully!");

The error is that it cannot find symbol "envelope in the second try block. Does the scope of try catch not extend outside? Any suggestions on how to go about fixing this?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: santiagozky is an unknown quantity at this point 
Solved Threads: 3
santiagozky santiagozky is offline Offline
Newbie Poster
 
0
  #2
Nov 4th, 2009
Originally Posted by krusso88 View Post
For a computer networking course I was given a project to make a Mail User Agent. We were given a few completed classes, but one of them is giving an error. Here is the part of code in question:

  1. try {
  2. Envelope envelope = new Envelope(mailMessage,
  3. serverField.getText());
  4. } catch (UnknownHostException e) {
  5. /* If there is an error, do not go further */
  6. return;
  7. }
  8. try {
  9. SMTPConnection connection = new SMTPConnection(envelope);
  10. connection.send(envelope);
  11. connection.close();
  12. } catch (IOException error) {
  13. System.out.println("Sending failed: " + error);
  14. return;
  15. }
  16. System.out.println("Mail sent succesfully!");

The error is that it cannot find symbol "envelope in the second try block. Does the scope of try catch not extend outside? Any suggestions on how to go about fixing this?

envelope is declared inside the first Try block so its scope finish there.
If you wish to use envelope in the second try block. Declare outside the try block.

  1.  
  2. Envelope envelope=null;
  3. try {
  4. envelope = new Envelope(mailMessage,
  5. serverField.getText());
  6. } catch (UnknownHostException e) {
  7. /* If there is an error, do not go further */
  8. return;
  9. }
  10. try {
  11. SMTPConnection connection = new SMTPConnection(envelope);
  12. connection.send(envelope);
  13. connection.close();
  14. } catch (IOException error) {
  15. System.out.println("Sending failed: " + error);
  16. return;
  17. }
  18. System.out.println("Mail sent succesfully!");
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC