944,117 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1440
  • Java RSS
Nov 4th, 2009
0

Mail User Agent

Expand 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:

Java Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krusso88 is offline Offline
9 posts
since Oct 2007
Nov 4th, 2009
0
Re: Mail User Agent
Click to Expand / Collapse  Quote originally posted by krusso88 ...
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:

Java Syntax (Toggle Plain Text)
  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.

Java Syntax (Toggle Plain Text)
  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!");
Reputation Points: 11
Solved Threads: 3
Newbie Poster
santiagozky is offline Offline
18 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to change application design? (custom jFrame, buttons)
Next Thread in Java Forum Timeline: How to add QMainWindow





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC