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