Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/try-005.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'try-005.js';
7
8 /**
9 * File Name: try-005.js
10 * ECMA Section:
11 * Description: The try statement
12 *
13 * This test has a try with one catch block but no finally. Same
14 * as try-004, but the eval statement is called from a function, not
15 * directly from within the try block.
16 *
17 * Author: [email protected]
18 * Date: 11 August 1998
19 */
20 var SECTION = "try-005";
21 var VERSION = "ECMA_2";
22 var TITLE = "The try statement";
23
24 startTest();
25 writeHeaderToLog( SECTION + " "+ TITLE);
26
27 TryToCatch( "Math.PI", Math.PI );
28 TryToCatch( "Thrower(5)", "Caught 5" );
29 TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" );
30
31 test();
32
33 function Thrower( v ) {
34 throw "Caught " + v;
35 }
36 function Eval( v ) {
37 return eval( v );
38 }
39
40 /**
41 * Evaluate a string. Catch any exceptions thrown. If no exception is
42 * expected, verify the result of the evaluation. If an exception is
43 * expected, verify that we got the right exception.
44 */
45
46 function TryToCatch( value, expect ) {
47 try {
48 result = Eval( value );
49 } catch ( e ) {
50 result = e;
51 }
52
53 new TestCase(
54 SECTION,
55 "eval( " + value +" )",
56 expect,
57 result );
58 }