# Error in Java file: cannot find symbol



## tenec (Aug 7, 2009)

When I attempt to compile the file I get this error: "UsingExceptions.java:11: cannot find symbol
symbol : method throwException()
location: class UsingExceptions
throwException(); // call method throwException
^ 
code
public class UsingExceptions
{ 
public static void main( String args[] )
{
try
{
throwException(); // call method throwException
} // end try
catch ( Exception exception ) // exception thrown by throwException
{
System.err.println( "Exception handled in main" );
} // end catch
}

public static void doesNotThrowException()
{
try // block does not throw an exception 
{

System.out.println( "Method doesNotThrowException" );
} // end method doesNotThrowException
catch ( Exception exception ) // does not execute
{
System.err.println( exception );
} // end catch
finally // executes regardless what occurs in try...catch
{
System.err.println( "finally executed in doesNotthrowException" );
} // end finally

System.out.println( "End of method doesNotThrowException" );
} 
// demonstrate try...catch...Exception
public static void throwExceptionB() throws Exception
{
try // throw an exception and immediately catch it
{
System.out.println( "Method throwExceptionB" );
throw new Exception(); // generate exception
} // end try
catch ( Exception exception ) // catch exception thrown in try
{
System.err.println(
"Exception handled in method throwException" );
throw exception; // rethrow for further processing

} // end catch
finally // executes regardless of what occurs in try...catch
{
System.err.println( "finally executed in throwException" );
} // end finally

} // end method throwExceptionA

// demonstrate try...catch...Exception
//public static void throwException() throws Exception
{
try // throw an exception and immediately catch it
{
System.out.println( "Method throwException" );
throw new Exception(); // generate exception
} // end try
catch ( Exception exception ) // catch exception thrown in try
{
System.err.println(
"Exception handled in method throwException" );
//throw exception; // rethrow for further processing

} // end catch
finally // executes regardless of what occurs in try...catch
{
System.err.println( "finally executed in throwException" );
} // end finally

} // end method throwExceptionB

// demonstrate try...catch...NullPointer
public static void throwExceptionNullPointer() throws Exception
{
try // throw an exception and immediately catch it
 {
System.out.println( "Method throwException" );
throw new Exception(); // generate exception
} // end try
catch ( Exception exception ) // catch exception thrown in try
{
System.err.println(
"Exception handled in method throwException" );
throw exception; // rethrow for further processing

} // end catch
finally // executes regardless of what occurs in try...catch
{
System.err.println( "finally executed in throwException" );
} // end finally

} // end method throwExceptionNullPointer

// demonstrate try...catch...ExceptionIO
public static void throwExceptionIO() throws Exception
{
try // throw an exception and immediately catch it
{
System.out.println( "Method throwException" );
throw new Exception(); // generate exception
} // end try
catch ( Exception exception ) // catch exception thrown in try
{
System.err.println(
"Exception handled in method throwException" );
throw exception; // rethrow for further processing

} // end catch
finally // executes regardless of what occurs in try...catch
{
System.err.println( "finally executed in throwException" );
} // end finally

} // end method throwExceptionIO

}// end class UsingExceptions

Code


----------



## NeonFx (Oct 22, 2008)

You don't have a method called throwException();


----------



## JimmySeal (Sep 25, 2007)

Or rather, you have a throwException method, but you have blocked it out with a pair of forward slashes //.

When you post your code, please enclose it in [code][/code] tags instead of just writing the word code at the beginning and end.


----------



## tenec (Aug 7, 2009)

Thanx Jimmy Seal and neonfx

throwException method, was definitely the problem. It had been commented out. I don't know how I managed to overlook it. 


Thanx


----------

