eclipse - Java - Error-message displaying incorrectly -
this isn't major issue, don't understand why happens, figured i'd post here. code:
do{ printmenu();//method print menu try{ user=input.nextint(); } catch(inputmismatchexception imme) { system.err.println("make sure enter number."); input.next(); continue; } switchmenu(user);//method switch method user input }while(1<2); the code runs fine except 1 thing. error message make sure enter number. displays after menu, before, in middle of menu. this output of program:
1. book ticket 2. cancel ticket 3. check how many seats left 4. print seat map 5. check price 6. print ticket 7. exit 1. book ticket 2. cancel ticket 3. check how many seats left 4. print seat map 5. check price 6. print ticket 7. exit make sure enter number.//error message after menu asd//wrong input make sure enter number.//now error message displays before menu 1. book ticket 2. cancel ticket 3. check how many seats left 4. print seat map 5. check price 6. print ticket 7. exit asd 1. book ticket 2. cancel ticket 3. check how many seats left make sure enter number.//in middle now??? 4. print seat map 5. check price 6. print ticket 7. exit i using eclipse if matters. know it's not big problem, i'm curious why happens.
this due fact system.out , system.err 2 different streams might buffer write operations , flushed (i.e. printed out) @ different times.
things mixed between system.out , system.err, because i'd assume system.out implemented using buffered output stream performance reasons , system.err implemented using non-buffered stream error messages printed more quickly.
you observe behaviour closer expect when explicitly call flush() on streams, although i'm not sure if there won't race conditions left, both end in same eclipse console.
that being said, i'd assume eclipse console has means of mixing strings (i.e. if code guarantees order, console might give system.err higher priority), reliable way of getting guaranteed order imho using same output stream both messages.
Comments
Post a Comment