michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: * File Name: try-009.js michael@0: * ECMA Section: michael@0: * Description: The try statement michael@0: * michael@0: * This test has a try block within a while block. Verify that an exception michael@0: * breaks out of the while. I don't really know why this is an interesting michael@0: * test case but Mike Shaver had two of these so what the hey. michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "try-009"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "The try statement: try in a while block"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var EXCEPTION_STRING = "Exception thrown: "; michael@0: var NO_EXCEPTION_STRING = "No exception thrown: "; michael@0: michael@0: michael@0: TryInWhile( new TryObject( "hello", ThrowException, true ) ); michael@0: TryInWhile( new TryObject( "aloha", NoException, false )); michael@0: michael@0: test(); michael@0: michael@0: function TryObject( value, throwFunction, result ) { michael@0: this.value = value; michael@0: this.thrower = throwFunction; michael@0: this.result = result; michael@0: } michael@0: function ThrowException() { michael@0: throw EXCEPTION_STRING + this.value; michael@0: } michael@0: function NoException() { michael@0: return NO_EXCEPTION_STRING + this.value; michael@0: } michael@0: function TryInWhile( object ) { michael@0: result = null; michael@0: while ( true ) { michael@0: try { michael@0: object.thrower(); michael@0: result = NO_EXCEPTION_STRING + object.value; michael@0: break; michael@0: } catch ( e ) { michael@0: result = e; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "( "+ object +".thrower() )", michael@0: (object.result michael@0: ? EXCEPTION_STRING + object.value : michael@0: NO_EXCEPTION_STRING + object.value), michael@0: result ); michael@0: }