langtools/src/jdk.jshell/share/classes/jdk/jshell/Eval.java
changeset 40769 e57f1a5c9346
parent 39807 ba0ff343d241
child 41514 a75c2b869d8d
equal deleted inserted replaced
40768:8b6a878d8773 40769:e57f1a5c9346
   553                     value = si.subKind().hasValue()
   553                     value = si.subKind().hasValue()
   554                             ? expunge(value)
   554                             ? expunge(value)
   555                             : "";
   555                             : "";
   556                 } catch (ResolutionException ex) {
   556                 } catch (ResolutionException ex) {
   557                     DeclarationSnippet sn = (DeclarationSnippet) state.maps.getSnippetDeadOrAlive(ex.id());
   557                     DeclarationSnippet sn = (DeclarationSnippet) state.maps.getSnippetDeadOrAlive(ex.id());
   558                     exception = new UnresolvedReferenceException(sn, ex.getStackTrace());
   558                     exception = new UnresolvedReferenceException(sn, translateExceptionStack(ex));
   559                 } catch (UserException ex) {
   559                 } catch (UserException ex) {
   560                     exception = translateExecutionException(ex);
   560                     exception = new EvalException(translateExceptionMessage(ex),
       
   561                             ex.causeExceptionClass(),
       
   562                             translateExceptionStack(ex));
   561                 } catch (RunException ex) {
   563                 } catch (RunException ex) {
   562                     // StopException - no-op
   564                     // StopException - no-op
   563                 } catch (InternalException ex) {
   565                 } catch (InternalException ex) {
   564                     state.debug(ex, "invoke");
   566                     state.debug(ex, "invoke");
   565                 } catch (EngineTerminationException ex) {
   567                 } catch (EngineTerminationException ex) {
   730                 state.closeDown();
   732                 state.closeDown();
   731             }
   733             }
   732         }
   734         }
   733     }
   735     }
   734 
   736 
   735     private EvalException translateExecutionException(UserException ex) {
   737     private StackTraceElement[] translateExceptionStack(Exception ex) {
   736         StackTraceElement[] raw = ex.getStackTrace();
   738         StackTraceElement[] raw = ex.getStackTrace();
   737         int last = raw.length;
   739         int last = raw.length;
   738         do {
   740         do {
   739             if (last == 0) {
   741             if (last == 0) {
   740                 last = raw.length - 1;
   742                 last = raw.length - 1;
   757                 elems[i] = new StackTraceElement(r.getClassName(), r.getMethodName(), null, r.getLineNumber());
   759                 elems[i] = new StackTraceElement(r.getClassName(), r.getMethodName(), null, r.getLineNumber());
   758             } else {
   760             } else {
   759                 elems[i] = r;
   761                 elems[i] = r;
   760             }
   762             }
   761         }
   763         }
       
   764         return elems;
       
   765     }
       
   766 
       
   767     private String translateExceptionMessage(Exception ex) {
   762         String msg = ex.getMessage();
   768         String msg = ex.getMessage();
   763         if (msg.equals("<none>")) {
   769         return msg.equals("<none>")
   764             msg = null;
   770                 ? null
   765         }
   771                 : msg;
   766         return new EvalException(msg, ex.causeExceptionClass(), elems);
       
   767     }
   772     }
   768 
   773 
   769     private boolean isWrap(StackTraceElement ste) {
   774     private boolean isWrap(StackTraceElement ste) {
   770         return PREFIX_PATTERN.matcher(ste.getClassName()).find();
   775         return PREFIX_PATTERN.matcher(ste.getClassName()).find();
   771     }
   776     }