java - How to debug try and catch blocks? -
i wondering if there can me out these 2 debugging assignments in java, involving try/catch/throw statements. can't seem figure out how debug either assignment working in netbeans zip file attached.
all or appreciated. thanks.
assignment 1:
package debugmeone; import java.io.file; import java.io.filenotfoundexception; import java.util.scanner; /* * file requires debugging. partial file read text file * simple error checking. if file not found (you testing this) * filenotfoundexception should thrown. second catch statement * producing error (red stop sign). why? job have both * exception , filenotfoundexception in file. not remove either 1 * of them. don't create file accountrecords.txt; testing * file not found condition there no need create file. * * output should be: * * run: * error - file not found: accountrecords.txt * java result: 100 * build successful (total time: 0 seconds) */ public class readtextfile { private scanner input; // ignore hint given netbeans public void openfile() { try { input = new scanner( new file("accountrecords.txt")); } catch(exception e) { system.out.println("something bad happened here."); system.exit(707); } // debug line; should solve error message? // read error message provided ide catch( filenotfoundexception fnfe) { system.out.println("error - file not found: accountrecords.txt"); system.exit(100); } } }
assignment 2:
package debugmetwo; /* * need debug file. * * output should be: * * run: * there problem eagle! * java result: 9999 * build successful (total time: 0 seconds) */ public class throweagleexceptiontest { public static void main(string[] args) { try { eaglelanding(); } catch (eaglelandingexception badeagle) { system.out.printf("%s\n", badeagle.getmessage()); system.exit(9999); } } private static void eaglelanding { eaglelandingexception("there problem eagle!"); } }
you have compile time error message, not runtime 1 debugger for. message read is
// debug line; should solve error message? // read error message provided ide catch( filenotfoundexception fnfe)
you expected read error message provided in ide , fix it. hint: specific exception have come first.
you second example won't compile either. need make compile throwing exception. if don't know how that, @ example.
Comments
Post a Comment