java - Cant pinpoint issue of when user inputs number less than 0 for my custom exception -
cant seem figure this. if user inputs invalid balance, how can reprompt them enter balance again , still continue program?
//edited still wont work boolean again; while(again = true) { try { // pass object printwriter , pw write file pw = new printwriter(fw); system.out.print("input beginnning balance: "); balance = input.nextdouble(); again = false; // pass user input object accountwithexception acctexception = new accountwithexception(fullname, balance, id, rate); again = false; system.out.println(acctexception.tostring()); // copy object created file pw.println(acctexception.tostring()); again = false; // custom exception } catch (invalidbalanceexception e) { system.out.println(e.getmessage()); } catch(filenotfoundexception e) { system.out.println(e.getmessage()); } { pw.close();
you can throw invalidbalanceexception
, catch in catch block this
try { // pass object printwriter , pw write file pw = new printwriter(fw); // pass user input object accountwithexception acctexception = new accountwithexception(fullname, balance, id, rate); system.out.println(acctexception.tostring()); // copy object created file pw.println(acctexception.tostring()); throw new invalidbalanceexception (); // custom exception if balance < 0 } catch (invalidbalanceexception e) { system.out.println(e.getmessage()); system.out.println("re-enter balance: "); balance = input.nextdouble(); } catch(filenotfoundexception e) { system.out.println(e.getmessage()); } { system.out.println("text file closed, program complete..."); pw.close(); }
Comments
Post a Comment