From 22ec5b89f053830f5ed3798abc28bd23ff7ca6a2 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 26 Jul 2016 21:46:30 +0300 Subject: Rename BorkError to TunkkiError --- .../com/jantuomi/tunkki/exception/BorkError.java | 61 ---------------------- .../tunkki/exception/ExceptionManager.java | 4 +- .../com/jantuomi/tunkki/exception/TunkkiError.java | 61 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 63 deletions(-) delete mode 100644 src/main/com/jantuomi/tunkki/exception/BorkError.java create mode 100644 src/main/com/jantuomi/tunkki/exception/TunkkiError.java (limited to 'src/main/com/jantuomi/tunkki/exception') diff --git a/src/main/com/jantuomi/tunkki/exception/BorkError.java b/src/main/com/jantuomi/tunkki/exception/BorkError.java deleted file mode 100644 index 6c7c2a1..0000000 --- a/src/main/com/jantuomi/tunkki/exception/BorkError.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.jantuomi.tunkki.exception; - - -import java.util.HashMap; -import java.util.Map; - -/** - * Created by jan on 12.6.2016. - */ -public class BorkError extends Exception { - - public enum ExceptionType { - IllegalTokenError, - SyntaxError, - TypeError, - ArgumentError, - UndeclaredSymbolError, - IncludeError, - GeneralError - } - - public static Map 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]."); - errorTexts.put(ExceptionType.IncludeError, "File %s could not be included."); - errorTexts.put(ExceptionType.GeneralError, "%s"); - } - - private ExceptionType exceptionType; - private String completeMessage; - - public BorkError(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); - if (line == -1) { - return "\n" + message; - } else { - 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); - } -} diff --git a/src/main/com/jantuomi/tunkki/exception/ExceptionManager.java b/src/main/com/jantuomi/tunkki/exception/ExceptionManager.java index 7c7a6b5..9cfdd2e 100644 --- a/src/main/com/jantuomi/tunkki/exception/ExceptionManager.java +++ b/src/main/com/jantuomi/tunkki/exception/ExceptionManager.java @@ -14,8 +14,8 @@ public class ExceptionManager { return instance; } - public static void raise(BorkError.ExceptionType ex, int line, String... args) throws BorkError { - BorkError e = new BorkError(ex, line, args); + public static void raise(TunkkiError.ExceptionType ex, int line, String... args) throws TunkkiError { + TunkkiError e = new TunkkiError(ex, line, args); throw e; } } diff --git a/src/main/com/jantuomi/tunkki/exception/TunkkiError.java b/src/main/com/jantuomi/tunkki/exception/TunkkiError.java new file mode 100644 index 0000000..b75398a --- /dev/null +++ b/src/main/com/jantuomi/tunkki/exception/TunkkiError.java @@ -0,0 +1,61 @@ +package com.jantuomi.tunkki.exception; + + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by jan on 12.6.2016. + */ +public class TunkkiError extends Exception { + + public enum ExceptionType { + IllegalTokenError, + SyntaxError, + TypeError, + ArgumentError, + UndeclaredSymbolError, + IncludeError, + GeneralError + } + + public static Map 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]."); + errorTexts.put(ExceptionType.IncludeError, "File %s could not be included."); + errorTexts.put(ExceptionType.GeneralError, "%s"); + } + + private ExceptionType exceptionType; + private String completeMessage; + + public TunkkiError(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); + if (line == -1) { + return "\n" + message; + } else { + 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); + } +} -- cgit v1.3