View Single Post
Old Apr 29th, 2008, 8:17 AM   #3
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Re: Try and Catch Statements

Quote:
Originally Posted by Freaky Chris View Post
The reason behind this is bracket placement, what you have actually done in yurs is place the catch statement within the try statement

Note i have also removed the else statement.
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

I never got to see the error because I figured out rather quickly with you clue. Thanks, I wasn't throwing an exception, I never had the statement. I put it in their and now I am receiving the illegal input error correctly. Now I just have to modify my questions and call the exception for every question. Thanks again. This was the code after I modified it with your help.

import java.io.*;

class ModifiedTest_Tester
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
        String strInput;

        System.out.println("Do you like Rock Music?:");
        strInput = dataIn.readLine();  //reads data from console
try
{
        
	if ("y".equals(strInput))
        {
            System.out.println("Do you like Marilyn Manson?:");
            strInput = dataIn.readLine();  //reads data from console
            if ("y".equals(strInput))
            {
                System.out.println("You are a hardcore Rocker");
            }
            else if ("n".equals(strInput))
            {
                System.out.println("How could you not like Marilyn Manson?");
            }
            else
            {
        		throw new TheException(); //calls
            }
        }
        else if ("n".equals(strInput))
        {
            System.out.println("Ok, bye rock hater!");
        }
}
	catch (TheException e)
        {
            System.out.println("Illegal input caught");
        }

        System.out.println();
        System.out.println("Program Ending!");
	}
    }
kewlgeye is offline   Reply With Quote