diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2016-06-20 20:55:22 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2016-07-26 19:47:02 +0300 |
| commit | d745f000d6d60b9cdf0ba40dbf80660c1aa6bc61 (patch) | |
| tree | e00ea32ae3a2d291768084544cb21429281dc0ae /main/exception | |
| parent | d35a37a449d31e6f4b43b937abf7b0e1fc497828 (diff) | |
Implemented general enhancements
Diffstat (limited to 'main/exception')
| -rw-r--r-- | main/exception/ExceptionManager.java | 4 | ||||
| -rw-r--r-- | main/exception/InterpreterException.java | 18 |
2 files changed, 10 insertions, 12 deletions
diff --git a/main/exception/ExceptionManager.java b/main/exception/ExceptionManager.java index dbb59d3..2dd46f5 100644 --- a/main/exception/ExceptionManager.java +++ b/main/exception/ExceptionManager.java @@ -1,7 +1,5 @@ package com.jantuomi.interpreter.main.exception; -import java.util.List; - /** * Created by jan on 10.6.2016. */ @@ -16,7 +14,7 @@ public class ExceptionManager { return instance; } - public static void raise(InterpreterException.ExceptionType ex, int line, List<String> args) throws InterpreterException { + 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 index 26e39fd..1565df9 100644 --- a/main/exception/InterpreterException.java +++ b/main/exception/InterpreterException.java @@ -2,7 +2,6 @@ package com.jantuomi.interpreter.main.exception; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -14,7 +13,8 @@ public class InterpreterException extends Exception { IllegalTokenError, UnknownOperatorError, SyntaxError, - TypeError + TypeError, + ArgumentError } public static Map<ExceptionType, String> errorTexts = new HashMap<>(); @@ -24,20 +24,20 @@ public class InterpreterException extends Exception { errorTexts.put(ExceptionType.UnknownOperatorError, "Unexpected operator %s found."); errorTexts.put(ExceptionType.SyntaxError, "Unexpected %s."); errorTexts.put(ExceptionType.TypeError, "Incompatible types %s and %s."); + errorTexts.put(ExceptionType.ArgumentError, "Function %s requires %s arguments."); } private ExceptionType exceptionType; - public InterpreterException(ExceptionType exceptionType, int line, List<String> args) { - super(formatMessage(exceptionType.toString() + what(exceptionType), line, args)); + public InterpreterException(ExceptionType exceptionType, int line, String... args) { + super(formatMessage(exceptionType.toString() + ": " + what(exceptionType), line, args), null, false, false); this.exceptionType = exceptionType; } - private static String formatMessage(String message, int line, List<String> args) { - for (String arg : args) { - message = String.format(message, arg); - } - return String.format("line %d: ", line) + message; + 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) { |
