1 package com.teamkonzept.lib.math; 2 3 4 public class MalformedExpressionException extends Exception { 5 6 final static int SYNTAX_ERROR = 0; 7 final static int MISSING_OPENING_PAREN = 1; 8 final static int MISSING_CLOSING_PAREN = 2; 9 final static int UNKNOWN_RESULT = 3; 10 11 int type; 12 int position; 13 14 public MalformedExpressionException(int type, int position){ 15 this.type = type; 16 this.position = position; 17 } 18 19 public String toString(){ 20 String res; 21 switch ( type ){ 22 case SYNTAX_ERROR: 23 res = "syntax error"; 24 break; 25 case MISSING_OPENING_PAREN: 26 res = "missing opening paren"; 27 break; 28 case MISSING_CLOSING_PAREN: 29 res = "missing closing paren"; 30 break; 31 case UNKNOWN_RESULT: 32 res = "result has wrong type"; 33 break; 34 default: 35 res = "syntax error"; 36 } 37 return res + " at position " + position; 38 } 39 } 40 | Popular Tags |