Can anyone tell me where I'm going wrong in my program to get this error? I've put an "*" next to the lines which give me this error. Using Eclipse btw. The whole code is linked below. Thanks!!
public static void main(String[] args)
{
openFile();
addRecords();
closeFile();
}
public static void openFile()
{
try
*{
* output = new Formatter("numbers.txt");
*}
*catch
{
System.err.println("Write permission denied. Terminating.");
System.exit(1);
}
*catch
{
System.err.println("Error opening file. Terminating.");
System.exit(1);
}
}
Your catch
clause is an exception handler which takes in an argument. The argument type, ExceptionType must be declared and must be the name of a class that inherits from the Throwable
class. I see your try-catch
block is not specifying an argument to either of the catch
clauses.
Refer to the method addRecords()
in the code you have referenced on pastebin for an example of correct exception handling.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.