The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Java style question. by dodrian 2007-03-04 09:37:08
Most of my Java assignments require the program I'm writing (at the moment a simple postfix expression evaluator) to gracefully handle invalid input. So far I've done this by including various checks along the way, like the following which makes sure there are two numbers in the stack before trying to operate on them:

if(s.size() < 2) //check expression can be operated on
{
System.out.println("This expression is not in postfix format.");
System.exit(1);
}

I seem to remember hearing somewhere that using System.exit(n) was frowned upon. What is your opinion on using System.exit(n) in the middle of code like this, and if you think it bad stylistically, how would you recommend I avoid it?

[ Reply ]
  Throw an exception. by williamashbless2007-03-04 09:48:55
    What he said. by aix tom2007-03-04 09:59:54
    Caveat! by SoylentGreen2007-03-04 12:11:09
  Have the user input an s that by s0205972007-03-04 12:19:52

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)