]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_2/Statements/try-004.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_2 / Statements / try-004.js
1 /**
2 * File Name: try-004.js
3 * ECMA Section:
4 * Description: The try statement
5 *
6 * This test has a try with one catch block but no finally.
7 *
8 * Author: christine@netscape.com
9 * Date: 11 August 1998
10 */
11 var SECTION = "try-004";
12 var VERSION = "ECMA_2";
13 var TITLE = "The try statement";
14
15 startTest();
16 writeHeaderToLog( SECTION + " "+ TITLE);
17
18 var tc = 0;
19 var testcases = new Array();
20
21 TryToCatch( "Math.PI", Math.PI );
22 TryToCatch( "Thrower(5)", "Caught 5" );
23 TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" );
24
25 test();
26
27 function Thrower( v ) {
28 throw "Caught " + v;
29 }
30
31 /**
32 * Evaluate a string. Catch any exceptions thrown. If no exception is
33 * expected, verify the result of the evaluation. If an exception is
34 * expected, verify that we got the right exception.
35 */
36
37 function TryToCatch( value, expect ) {
38 try {
39 result = eval( value );
40 } catch ( e ) {
41 result = e;
42 }
43
44 testcases[tc++] = new TestCase(
45 SECTION,
46 "eval( " + value +" )",
47 expect,
48 result );
49 }
50
51