I'm sorry AI choosse the wrong file

I'm sorry I choose the wrong file.

The error that I'm getting is this one:

Exception 'IOException' not caught or declared by 'void Lesson%.main(String[] args).

If I click the error and it take me to readLine() line, so I don't understand what happend.

Thanks

/**

* LESSON FIVE

*

* @author JAIME TORRES

* @version 1.0

*/

import java.io.* ;

class BadOpt extends Exception

{

public BadOpt( String option ) {}

public String BadOpt( String option )

{

if( option.equals("A") )

return(" Bad option: Caracas is the Capital of Venezuela") ;

if( option.equals("B") )

return(" Bad option: Santiago is the Capital of Chile" ) ;

else

return(" Bad option: Omaha is the bigest city in Nebraska" ) ;

}

}

class Lesson5

{

/*

* Constructor

*/

public Lesson5()

{} // empty

public static void main( String[] args)

{

String option = "D" ;

BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in) ) ;

while( ! ( option.equals("E") ) )

{

try

{

System.out.println() ;

System.out.print("Please choose the correct answer:");

System.out.println() ;

System.out.println(" What is the capital of Colombia?" ) ;

System.out.println(" A. Caracas");

System.out.println(" B. Santiago");

System.out.println(" C. Omaha") ;

System.out.println(" D. Bogota");

System.out.println() ;

System.out.print("Your option is? " ) ;

option = stdin.readLine() ;

if( ! (option.equals("A")) )

throw (new BadOpt(option) );

}

catch ( BadOpt e )

{

System.out.println( e.BadOpt(option) ) ;

} // End catch block

} // End while loop

}

}

[1877 byte] By [jaltoro] at [2007-9-26 2:22:31]
# 1

Hi,

The readLine() method can throw an IOException. You'll need to catch it as follows:

try

{

...

}

catch ( BadOpt e )

{

System.out.println( e.BadOpt(option) ) ;

}

catch ( IOException e )

{

System.out.println( e.getMessage() ) ;

}

Hope this helps,

Kurt.

leukbr at 2007-6-29 9:29:14 > top of Java-index,Archived Forums,Java Programming...
# 2
Since u r using IO method called readLine(), it will throw an IOException which should be caught..so include another catch loop in your try block..catch(IOException e){ e.printStackTrace();}Saran
saran_v at 2007-6-29 9:29:14 > top of Java-index,Archived Forums,Java Programming...