| 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? |