diff options
Diffstat (limited to 'main/exception')
| -rw-r--r-- | main/exception/ExceptionManager.java | 29 | ||||
| -rw-r--r-- | main/exception/InterpreterException.java | 33 |
2 files changed, 62 insertions, 0 deletions
diff --git a/main/exception/ExceptionManager.java b/main/exception/ExceptionManager.java new file mode 100644 index 0000000..0ceb25b --- /dev/null +++ b/main/exception/ExceptionManager.java @@ -0,0 +1,29 @@ +package com.jantuomi.interpreter.main.exception; + +import java.util.List; + +/** + * Created by jan on 10.6.2016. + */ +public class ExceptionManager { + + private static final ExceptionManager instance = new ExceptionManager(); + + private ExceptionManager() { + } + + public static ExceptionManager getInstance() { + return instance; + } + + public static void raise(InterpreterException.Exception ex, int line, List<String> args) { + InterpreterException e = new InterpreterException(ex); + String output = e.what(); + for (String arg : args) { + output = String.format(output, arg); + } + System.err.println(String.format("[%s] line: %d %s", ex.toString(), line, output)); + } + + +} diff --git a/main/exception/InterpreterException.java b/main/exception/InterpreterException.java new file mode 100644 index 0000000..8129012 --- /dev/null +++ b/main/exception/InterpreterException.java @@ -0,0 +1,33 @@ +package com.jantuomi.interpreter.main.exception; + + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by jan on 12.6.2016. + */ +public class InterpreterException { + + public enum Exception { + IllegalTokenException, + UnknownOperatorException + } + + public static Map<Exception, String> errorTexts = new HashMap<>(); + + static { + errorTexts.put(Exception.IllegalTokenException, "Illegal token %s found."); + errorTexts.put(Exception.UnknownOperatorException, "Unknown operator %s found."); + } + + private Exception exception; + + public InterpreterException(Exception e) { + exception = e; + } + + public String what() { + return errorTexts.get(exception); + } +} |
