8139837: JShell API: make a common JShellException
authorrfield
Fri, 29 Apr 2016 19:53:19 -0700
changeset 37751 77e7bb904a13
parent 37750 d213951c811b
child 37752 4243173b58db
8139837: JShell API: make a common JShellException Reviewed-by: jlahoda
langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/EvalException.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/ExecutionControl.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/JShellException.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/SnippetEvent.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java
langtools/src/jdk.jshell/share/classes/jdk/jshell/UnresolvedReferenceException.java
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Fri Apr 29 15:35:51 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Fri Apr 29 19:53:19 2016 -0700
@@ -452,7 +452,7 @@
 
         // If appropriate, execute the snippet
         String value = null;
-        Exception exception = null;
+        JShellException exception = null;
         if (si.status().isDefined) {
             if (si.isExecutable()) {
                 try {
@@ -462,7 +462,8 @@
                             : "";
                 } catch (EvalException ex) {
                     exception = translateExecutionException(ex);
-                } catch (UnresolvedReferenceException ex) {
+                } catch (JShellException ex) {
+                    // UnresolvedReferenceException
                     exception = ex;
                 }
             } else if (si.subKind() == SubKind.VAR_DECLARATION_SUBKIND) {
@@ -499,7 +500,7 @@
                     || e.exception() != null;
     }
 
-    private List<SnippetEvent> events(Unit c, Collection<Unit> outs, String value, Exception exception) {
+    private List<SnippetEvent> events(Unit c, Collection<Unit> outs, String value, JShellException exception) {
         List<SnippetEvent> events = new ArrayList<>();
         events.add(c.event(value, exception));
         events.addAll(outs.stream()
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/EvalException.java	Fri Apr 29 15:35:51 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/EvalException.java	Fri Apr 29 19:53:19 2016 -0700
@@ -40,7 +40,7 @@
  * empty string.
  */
 @SuppressWarnings("serial")             // serialVersionUID intentionally omitted
-public class EvalException extends Exception {
+public class EvalException extends JShellException {
     private final String exceptionClass;
 
     EvalException(String message, String exceptionClass, StackTraceElement[] stackElements) {
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/ExecutionControl.java	Fri Apr 29 15:35:51 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/ExecutionControl.java	Fri Apr 29 19:53:19 2016 -0700
@@ -119,7 +119,7 @@
         }
     }
 
-    String commandInvoke(String classname) throws EvalException, UnresolvedReferenceException {
+    String commandInvoke(String classname) throws JShellException {
         try {
             synchronized (STOP_LOCK) {
                 userCodeRunning = true;
@@ -213,7 +213,7 @@
         }
     }
 
-    private boolean readAndReportExecutionResult() throws IOException, EvalException, UnresolvedReferenceException {
+    private boolean readAndReportExecutionResult() throws IOException, JShellException {
         int ok = in.readInt();
         switch (ok) {
             case RESULT_SUCCESS:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShellException.java	Fri Apr 29 19:53:19 2016 -0700
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.jshell;
+
+/**
+ * The superclass of JShell generated exceptions
+ */
+@SuppressWarnings("serial")             // serialVersionUID intentionally omitted
+public class JShellException extends Exception {
+
+    JShellException(String message) {
+        super(message);
+    }
+}
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/SnippetEvent.java	Fri Apr 29 15:35:51 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/SnippetEvent.java	Fri Apr 29 19:53:19 2016 -0700
@@ -44,7 +44,7 @@
 
     SnippetEvent(Snippet snippet, Status previousStatus, Status status,
             boolean isSignatureChange, Snippet causeSnippet,
-            String value, Exception exception) {
+            String value, JShellException exception) {
         this.snippet = snippet;
         this.previousStatus = previousStatus;
         this.status = status;
@@ -60,7 +60,7 @@
     private final boolean isSignatureChange;
     private final Snippet causeSnippet;
     private final String value;
-    private final Exception exception;
+    private final JShellException exception;
 
     /**
      * The Snippet which has changed
@@ -121,7 +121,7 @@
      * during execution, otherwise <code>null</code>.
      * @return the exception or <code>null</code>.
      */
-    public Exception exception() {
+    public JShellException exception() {
         return exception;
     }
 
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Fri Apr 29 15:35:51 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java	Fri Apr 29 19:53:19 2016 -0700
@@ -440,7 +440,7 @@
                 : msi.parameterTypes();
     }
 
-    SnippetEvent event(String value, Exception exception) {
+    SnippetEvent event(String value, JShellException exception) {
         boolean wasSignatureChanged = sigChanged();
         state.debug(DBG_EVNT, "Snippet: %s id: %s before: %s status: %s sig: %b cause: %s\n",
                 si, si.id(), prevStatus, si.status(), wasSignatureChanged, causalSnippet);
--- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/UnresolvedReferenceException.java	Fri Apr 29 15:35:51 2016 -0700
+++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/UnresolvedReferenceException.java	Fri Apr 29 19:53:19 2016 -0700
@@ -38,7 +38,7 @@
  * empty string.
  */
 @SuppressWarnings("serial")             // serialVersionUID intentionally omitted
-public class UnresolvedReferenceException extends Exception {
+public class UnresolvedReferenceException extends JShellException {
 
     final DeclarationSnippet snippet;