Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/liveconnect/exception/Exception_001.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package com.netscape.javascript.qa.liveconnect.exception;
6
7 import com.netscape.javascript.qa.liveconnect.*;
8 import netscape.javascript.JSObject;
9 import netscape.javascript.JSException;
10
11 /**
12 * Evaluate a string that should cause a JavaScript exception. Verify
13 * that an exception was thrown, and get the exception message.
14 *
15 * @see netscape.javascript.JSObject
16 *
17 * @author christine m begle
18 */
19
20 public class Exception_001 extends LiveConnectTest {
21 public Exception_001() {
22 super();
23 }
24
25 public static void main( String[] args ) {
26 Exception_001 test = new Exception_001();
27 test.start();
28 }
29 public void executeTest() {
30 String result = "No exception thrown.";
31
32 try {
33 // the following statement should throw a JavaScript exception,
34 // since foo is not defined
35
36 global.eval( "foo.bar = 999;" );
37
38 } catch (Exception e) {
39 if ( e instanceof JSException ) {
40 result = "JSException thrown!";
41 } else {
42 result = "Some random exception thrown!";
43 }
44
45 file.exception = e.toString();
46 e.printStackTrace();
47 } finally {
48 addTestCase(
49 "global.eval(\"foo.bar = 999\") should throw a JavaScript exception:",
50 "JSException thrown!",
51 result,
52 file.exception );
53 }
54 }
55 }