diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/runtime/Breakpoint.java b/vdmj/src/main/java/com/fujitsu/vdmj/runtime/Breakpoint.java index 331c269ee..aeda3edeb 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/runtime/Breakpoint.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/runtime/Breakpoint.java @@ -82,8 +82,6 @@ public class Breakpoint implements Serializable public static final int SOURCE = 0; // A file:line source breakpoint public static final int FUNCTION = 1; // A function or operation name breakpoint - public static final int USER_CANCEL = 4999; // Special message for timeouts - public Breakpoint(LexLocation location) { this.location = location; @@ -231,7 +229,7 @@ public void check(LexLocation execl, Context ctxt) case TERMINATE: setExecInterrupt(Breakpoint.NONE); - throw new ContextException(USER_CANCEL, "Execution cancelled", location, ctxt); + ContextException.throwUserCancel(location, ctxt); } ThreadState state = ctxt.threadState; diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/runtime/ContextException.java b/vdmj/src/main/java/com/fujitsu/vdmj/runtime/ContextException.java index d42d62d24..0b7e5971c 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/runtime/ContextException.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/runtime/ContextException.java @@ -29,7 +29,8 @@ @SuppressWarnings("serial") public class ContextException extends RuntimeException { - public static final int STACK_OVERFLOW = 4998; + private static final int STACK_OVERFLOW = 4998; + private static final int USER_CANCEL = 4999; public final LexLocation location; public final Context ctxt; @@ -56,13 +57,23 @@ public String toString() return getMessage(); } + public static void throwStackOverflow(LexLocation from, Context ctxt) throws ContextException + { + throw new ContextException(STACK_OVERFLOW, "Stack overflow", from, ctxt); + } + public boolean isStackOverflow() { return number == STACK_OVERFLOW; } + public static void throwUserCancel(LexLocation from, Context ctxt) throws ContextException + { + throw new ContextException(USER_CANCEL, "Execution cancelled", from, ctxt); + } + public boolean isUserCancel() { - return number == Breakpoint.USER_CANCEL; + return number == USER_CANCEL; } } diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/values/FunctionValue.java b/vdmj/src/main/java/com/fujitsu/vdmj/values/FunctionValue.java index 25b47fba2..05aae0456 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/values/FunctionValue.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/values/FunctionValue.java @@ -343,7 +343,8 @@ public Value eval( catch (StackOverflowError e) { clearData(); - throw new ContextException(ContextException.STACK_OVERFLOW, "Stack overflow", location, ctxt); + ContextException.throwStackOverflow(location, ctxt); + return null; // No reached } } @@ -366,7 +367,8 @@ public Value eval( catch (StackOverflowError e) { clearData(); - throw new ContextException(ContextException.STACK_OVERFLOW, "Stack overflow", location, ctxt); + ContextException.throwStackOverflow(location, ctxt); + return null; // No reached } } diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/values/OperationValue.java b/vdmj/src/main/java/com/fujitsu/vdmj/values/OperationValue.java index a56a79374..9a3163e55 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/values/OperationValue.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/values/OperationValue.java @@ -239,7 +239,8 @@ public Value eval(LexLocation from, ValueList argValues, Context ctxt) } catch (StackOverflowError e) { - throw new ContextException(ContextException.STACK_OVERFLOW, "Stack overflow", from, ctxt); + ContextException.throwStackOverflow(from, ctxt); + return null; // No reached } }