title: Using try-catch blocks for various exceptions (java)
body: <p>So I am trying to make a couple try-catch statements in my Postfix expression evaluator to catch exceptions that will come up from a input file. I just need help making those try-catch statements. </p>
  
  <p>So the current output is:</p>
  
  <pre><code>5
  2
  1
  8
  -4
  2
  -4
  Exception in thread "main" java.util.EmptyStackException
      at LinkedStack.pop(LinkedStack.java:44)
      at PostFix.postfixEvaluation(PostFix.java:171)
      at PostFix.readFromTheFile(PostFix.java:49)
      at PostFix.main(PostFix.java:21)
  </code></pre>
  
  <p>while I want it to output: </p>
  
  <pre><code>5
  2
  1
  8
  -4
  2
  -4
  ERROR: java.lang.RuntimeException: Bad character input: " "
  ERROR: java.util.EmptyStackException for 1+1
  ERROR: java.util.EmptyStackException for 11+*
  ERROR: java.util.EmptyStackException for +11
  ERROR: java.lang.RuntimeException: Bad character input: "@"
  </code></pre>
  
  <p>The input file contains: </p>
  
  <pre><code>   511+93/2-932/-149657%/*-+14+96*5/7%-149-+6*57%/     1+111+*+1111@
  </code></pre>
  
  <p>Here is my current method for the code, the try-catch blocks would go here:</p>
  
  <pre><code>  public static Integer postfixEvaluation(String input){
  
  
  
        StackInterface&lt;Integer&gt; stack = new LinkedStack&lt;Integer&gt;();
  
        Integer result = new Integer(0);
  
  
  
        for(int i=0;i&lt;input.length();i++){
  
           String characterNum = input.substring(i, i+1);
  
           Integer integer1 = new Integer(0);
           Integer integer2 = new Integer(0);
  
  
  
  
  
  
           if (characterNum.equals("0")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
  
           }
           else if (characterNum.equals("1")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
  
           }
           else if (characterNum.equals("2")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("3")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("4")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("5")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("6")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("7")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("8")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("9")) {
              Integer character = (Integer.valueOf(characterNum));
              stack.push(character);
           }
           else if (characterNum.equals("*")) {
              integer2 = stack.pop();
              integer1 = stack.pop();
  
  
              result = integer1 * integer2;
  
  
              stack.push(result);
  
  
  
           }
           else if (characterNum.equals("/")) {
              integer2 = stack.pop();
              integer1 = stack.pop();
  
              result = integer1 / integer2;
  
  
              stack.push(result);
  
           }
           else if (characterNum.equals("%")) {
              integer2 = stack.pop();
              integer1 = stack.pop();
  
  
              result = integer1 % integer2;
  
  
              stack.push(result);
           }
           else if (characterNum.equals("+")) {
              integer2 = stack.pop();
              integer1 = stack.pop();
  
  
              result = integer1 + integer2;
  
  
              stack.push(result);
  
           }
           else if (characterNum.equals("-")) {
              integer2 = stack.pop();
              integer1 = stack.pop();
  
              result = integer1 - integer2;
  
  
              stack.push(result);
  
           }
  
  
  
  
        }
       return result;
     }
  </code></pre>
  
  <p>Any help will be greatly appreciated</p>