aboutsummaryrefslogtreecommitdiffstats
path: root/main/exception
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2016-06-28 21:09:43 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2016-07-26 19:47:12 +0300
commit8f84c00978dc05007873a9fe1de6a18511dc3cf8 (patch)
tree39fead540e22addee40b95b68db08cbea620745b /main/exception
parent48dcd488054024d98fe1e659a4029630130d1d35 (diff)
Restructure project for use with maven
Diffstat (limited to 'main/exception')
-rw-r--r--main/exception/ExceptionManager.java21
-rw-r--r--main/exception/InterpreterException.java53
2 files changed, 0 insertions, 74 deletions
diff --git a/main/exception/ExceptionManager.java b/main/exception/ExceptionManager.java
deleted file mode 100644
index 7eabe14..0000000
--- a/main/exception/ExceptionManager.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.jantuomi.interpreter.main.exception;
-
-/**
- * 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.ExceptionType ex, int line, String... args) throws InterpreterException {
- InterpreterException e = new InterpreterException(ex, line, args);
- throw e;
- }
-}
diff --git a/main/exception/InterpreterException.java b/main/exception/InterpreterException.java
deleted file mode 100644
index 50fa2f0..0000000
--- a/main/exception/InterpreterException.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.jantuomi.interpreter.main.exception;
-
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created by jan on 12.6.2016.
- */
-public class InterpreterException extends Exception {
-
- public enum ExceptionType {
- IllegalTokenError,
- SyntaxError,
- TypeError,
- ArgumentError,
- UndeclaredSymbolError
- }
-
- public static Map<ExceptionType, String> errorTexts = new HashMap<>();
-
- static {
- errorTexts.put(ExceptionType.IllegalTokenError, "Unknown or illegal token %s found.");
- errorTexts.put(ExceptionType.SyntaxError, "Unexpected %s.");
- errorTexts.put(ExceptionType.TypeError, "Incompatible types %s and %s.");
- errorTexts.put(ExceptionType.ArgumentError, "The parameter list given to function %s is either of wrong length or the parameters are of wrong type. Actual: %s");
- errorTexts.put(ExceptionType.UndeclaredSymbolError, "No symbol %s defined, parameters: [%s].");
- }
-
- private ExceptionType exceptionType;
- private String completeMessage;
-
- public InterpreterException(ExceptionType exceptionType, int line, String... args) {
- super(exceptionType.toString(), null, false, false);
- this.exceptionType = exceptionType;
- this.completeMessage = formatMessage(exceptionType.toString() + ": " + what(exceptionType), line, args);
- }
-
- private static String formatMessage(String message, int line, String... args) {
-
- message = String.format(message, args);
- return String.format("\nline %d: ", line) + message;
- }
-
- public static String what(ExceptionType type) {
- return errorTexts.get(type);
- }
-
- @Override
- public void printStackTrace() {
- System.err.println(completeMessage);
- }
-}