blob: 439b947b2498a9d26eb4054f54c2710889ab3093 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 6474943
27 * @summary Test that Rhion exception messages are
28 * available from ScriptException.
29 */
30
31import java.io.*;
32import javax.script.*;
33
34public class RhinoExceptionTest {
35 private static final String ERROR_MSG = "error from JavaScript";
36
37 public static void main(String[] args) throws Exception {
38 ScriptEngineManager m = new ScriptEngineManager();
39 ScriptEngine engine = m.getEngineByName("js");
40 engine.put("msg", ERROR_MSG);
41 try {
42 engine.eval("throw new Error(msg);");
43 } catch (ScriptException exp) {
44 if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
45 throw exp;
46 }
47 }
48 try {
49 engine.eval("throw (msg);");
50 } catch (ScriptException exp) {
51 if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
52 throw exp;
53 }
54 }
55 try {
56 CompiledScript scr = ((Compilable)engine).compile("throw new Error(msg);");
57 scr.eval();
58 } catch (ScriptException exp) {
59 if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
60 throw exp;
61 }
62 }
63 try {
64 CompiledScript scr = ((Compilable)engine).compile("throw msg;");
65 scr.eval();
66 } catch (ScriptException exp) {
67 if (exp.getMessage().indexOf(ERROR_MSG) == -1) {
68 throw exp;
69 }
70 }
71 }
72}