1/** 2 * File Name: try-009.js 3 * ECMA Section: 4 * Description: The try statement 5 * 6 * This test has a try block within a while block. Verify that an exception 7 * breaks out of the while. I don't really know why this is an interesting 8 * test case but Mike Shaver had two of these so what the hey. 9 * 10 * Author: christine@netscape.com 11 * Date: 11 August 1998 12 */ 13 var SECTION = "try-009"; 14 var VERSION = "ECMA_2"; 15 var TITLE = "The try statement: try in a while block"; 16 17 startTest(); 18 writeHeaderToLog( SECTION + " "+ TITLE); 19 20 var tc = 0; 21 var testcases = new Array(); 22 23 var EXCEPTION_STRING = "Exception thrown: "; 24 var NO_EXCEPTION_STRING = "No exception thrown: "; 25 26 27 TryInWhile( new TryObject( "hello", ThrowException, true ) ); 28 TryInWhile( new TryObject( "aloha", NoException, false )); 29 30 test(); 31 32 function TryObject( value, throwFunction, result ) { 33 this.value = value; 34 this.thrower = throwFunction; 35 this.result = result; 36 } 37 function ThrowException() { 38 throw EXCEPTION_STRING + this.value; 39 } 40 function NoException() { 41 return NO_EXCEPTION_STRING + this.value; 42 } 43 function TryInWhile( object ) { 44 result = null; 45 while ( true ) { 46 try { 47 object.thrower(); 48 result = NO_EXCEPTION_STRING + object.value; 49 break; 50 } catch ( e ) { 51 result = e; 52 break; 53 } 54 } 55 56 testcases[tc++] = new TestCase( 57 SECTION, 58 "( "+ object +".thrower() )", 59 (object.result 60 ? EXCEPTION_STRING + object.value : 61 NO_EXCEPTION_STRING + object.value), 62 result ); 63 } 64