2 Replies - 765 Views - Last Post: 20 November 2011 - 11:02 AM Rate Topic: -----

#1 missy24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-December 09

Error can not find symbolI

Posted 19 November 2011 - 01:22 PM

I am attempting to create a custom class with chained exceptions. I keep getting error can not find symbol for TestException. Any help is appreciated.
import java.io.*;

public class CustomTesterApp
{
    public static void main(String[] args)
    {
        System.out.println("In main: calling Method1.");
        Method1();
        System.out.println("In main: returned from Method1.");
    }

    public static void Method1()
    {

        System.out.println("\tIn Method1: calling Method2.");
        Method2();

        System.out.println("\tIn Method1: returned from Method2.");

    }

    public static void Method2()
    {
		try
		{
        System.out.println("\t\tIn Method2: calling Method3.");
        Method3();
        }
		catch(IOException e)
		{
        System.out.println("\t\tIn Method2: returned from Method3.");
	    }
    }

    public static void Method3() //throws TestException
    {
       String input = "invalid input";

       try
        {
			throw new TestException(); //ERROR
			System.out.println("\t\t\tIn Method3: Entering.");

        //Add code to throw an exception here.
		//throw new IOException(e);

		}
		catch (TestException e) //ERROR

		{

        System.out.println("\t\t\tIn Method3: Exiting.");

	   }
    }
}



TestException class

import java.io.*;


public class TestException extends RuntimeException
{

	public TestException()
	{
	}

	public TestException(String message)
	{
		super(message); //accepts string message
	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: Error can not find symbolI

#2 missy24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-December 09

Re: Error can not find symbolI

Posted 19 November 2011 - 02:07 PM

I figured it out it had to do with my file directory
Was This Post Helpful? 0
  • +
  • -

#3 missy24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-December 09

Re: Error can not find symbolI

Posted 20 November 2011 - 11:02 AM

I am still having several problems with this program. When using System.out.println(e.getCause().toString()); an exception is being through. I believe I have covered most of the guidelines, except for #1 and # 6. I am also wondering if I covered 5 correctly. I appreciate any input on this. Thanks
Guidelines

1. Method3 throws TestException with a custom message
2.Method2 catches TestException and displays the message on the console
3.TestException has a constructor that takes a Throwable parameter
4. try statement in Method3 throws IOException
5. catch block in Method3 throws TestException, passing IOException to its constructor
6. catch block in Method2 displays original cause of exception
import java.io.*;
import java.lang.*;

	public class CustomTesterApp
	{
	    public static void main(String[] args)
	    {
	        System.out.println("In main: calling Method1.");
	        Method1();
	        System.out.println("In main: returned from Method1.");
	    }

	    public static void Method1()
	    {

	        System.out.println("\tIn Method1: calling Method2.");
	        Method2();

	        System.out.println("\tIn Method1: returned from Method2.");

	    }

	    public static void Method2()
	    {
	        try
	        {
	        System.out.println("\t\tIn Method2: calling Method3.");
	        Method3();

	        }
	        catch(TestException e)
	        {

	        System.out.println("\t\tIn Method2: returned from Method3.");
	        System.out.println(e.getCause().toString());

	        }
	    }

	    public static void Method3() throws TestException
	    {


	       try
	        {

	            System.out.println("\t\t\tIn Method3: Entering.");


	        //Add code to throw an exception here.
	        throw new IOException();

	        }
	        catch (IOException e)

	        {

			throw new TestException();


		   }

	    }
	}





public class TestException extends Exception
{

	public TestException()
	{
	}

	public TestException(String message)
	{
		super(message); //accepts string message
	}
	public TestException(Throwable cause)
	{
		super(cause);
	}

}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1