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-010.js michael@0: * ECMA Section: michael@0: * Description: The try statement michael@0: * michael@0: * This has a try block nested in the try block. Verify that the michael@0: * exception is caught by the right try block, and all finally blocks michael@0: * are executed. michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "try-010"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "The try statement: try in a tryblock"; 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: NestedTry( new TryObject( "No Exceptions Thrown", NoException, NoException, 43 ) ); michael@0: NestedTry( new TryObject( "Throw Exception in Outer Try", ThrowException, NoException, 48 )); michael@0: NestedTry( new TryObject( "Throw Exception in Inner Try", NoException, ThrowException, 45 )); michael@0: NestedTry( new TryObject( "Throw Exception in Both Trys", ThrowException, ThrowException, 48 )); michael@0: michael@0: test(); michael@0: michael@0: function TryObject( description, tryOne, tryTwo, result ) { michael@0: this.description = description; michael@0: this.tryOne = tryOne; michael@0: this.tryTwo = tryTwo; 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 NestedTry( object ) { michael@0: result = 0; michael@0: try { michael@0: object.tryOne(); michael@0: result += 1; michael@0: try { michael@0: object.tryTwo(); michael@0: result += 2; michael@0: } catch ( e ) { michael@0: result +=4; michael@0: } finally { michael@0: result += 8; michael@0: } michael@0: } catch ( e ) { michael@0: result += 16; michael@0: } finally { michael@0: result += 32; michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: object.description, michael@0: object.result, michael@0: result ); michael@0: }