View Single Post
Old Apr 29th, 2008, 1:51 AM   #2
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: Try and Catch Statements

The reason behind this is bracket placement, what you have actually done in yurs is place the catch statement within the try statement
Java Syntax (Toggle Plain Text)
  1. try
  2. {
  3.  
  4. if ("y".equals(strInput))
  5. {
  6. System.out.println("Do you like Marilyn Manson?:");
  7. strInput = dataIn.readLine(); //reads data from console
  8. if ("y".equals(strInput))
  9. {
  10. System.out.println("You are a hardcore Rocker");
  11. }
  12. else if ("n".equals(strInput))
  13. {
  14. System.out.println("How could you not like Marilyn Manson?");
  15. }
  16. else
  17. {
  18. System.out.println("Illegal input: " + strInput);
  19. }
  20. }
  21. else if ("n".equals(strInput))
  22. {
  23. System.out.println("Ok, bye rock hater!");
  24. }
  25. }
  26. catch (TheException e)
  27. {
  28. System.out.println("" + e + " input: " + strInput);
  29. }
  30.  
  31. System.out.println();
  32. System.out.println("Program Ending!");
  33. }
  34. }

Note i have also removed the else statement. Now you will be given a different error converning the fact that TheException is never thrown in the try statement, this i'll let you look into.

If you do still need help on this just ask, but as a clue what exception are you trying to catch? and what throws it?


Cheers,
Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote