1 package jep.test;
2 
3 import jep.Interpreter;
4 import jep.JepConfig;
5 import jep.JepException;
6 import jep.SubInterpreter;
7 
8 /**
9  * Tests that a java exception thrown while executing Python is set as the cause
10  * of the JepException.
11  *
12  * Created: July 2017
13  *
14  * @author Ben Steffensmeier
15  */
16 public class TestExceptionCause {
17 
main(String[] args)18     public static void main(String[] args) throws JepException {
19         JepConfig config = new JepConfig().addIncludePaths(".");
20         try (Interpreter interp = new SubInterpreter(config)) {
21             interp.eval("from java.util import ArrayList");
22             try {
23                 interp.eval("ArrayList().get(0)");
24             } catch (JepException e) {
25                 if (!(e.getCause() instanceof IndexOutOfBoundsException)) {
26                     throw e;
27                 }
28             }
29             try {
30                 interp.eval(
31                         "try:\n  ArrayList().get(0)\nexcept AttributeError:\n  pass");
32             } catch (JepException e) {
33                 if (!(e.getCause() instanceof IndexOutOfBoundsException)) {
34                     throw e;
35                 }
36             }
37         }
38     }
39 
40 }
41