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-003.js michael@0: * ECMA Section: michael@0: * Description: The try statement michael@0: * michael@0: * This test has a try with no catch, and a finally. michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "try-003"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "The try statement"; michael@0: var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=313585"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // Tests start here. michael@0: michael@0: TrySomething( "x = \"hi\"", false ); michael@0: TrySomething( "throw \"boo\"", true ); michael@0: TrySomething( "throw 3", true ); michael@0: michael@0: test(); michael@0: michael@0: /** michael@0: * This function contains a try block with no catch block, michael@0: * but it does have a finally block. Try to evaluate expressions michael@0: * that do and do not throw exceptions. michael@0: */ michael@0: michael@0: function TrySomething( expression, throwing ) { michael@0: innerFinally = "FAIL: DID NOT HIT INNER FINALLY BLOCK"; michael@0: if (throwing) { michael@0: outerCatch = "FAILED: NO EXCEPTION CAUGHT"; michael@0: } else { michael@0: outerCatch = "PASS"; michael@0: } michael@0: outerFinally = "FAIL: DID NOT HIT OUTER FINALLY BLOCK"; michael@0: michael@0: try { michael@0: try { michael@0: eval( expression ); michael@0: } finally { michael@0: innerFinally = "PASS"; michael@0: } michael@0: } catch ( e ) { michael@0: if (throwing) { michael@0: outerCatch = "PASS"; michael@0: } else { michael@0: outerCatch = "FAIL: HIT OUTER CATCH BLOCK"; michael@0: } michael@0: } finally { michael@0: outerFinally = "PASS"; michael@0: } michael@0: michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "eval( " + expression +" )", michael@0: "PASS", michael@0: innerFinally ); michael@0: new TestCase( michael@0: SECTION, michael@0: "eval( " + expression +" )", michael@0: "PASS", michael@0: outerCatch ); michael@0: new TestCase( michael@0: SECTION, michael@0: "eval( " + expression +" )", michael@0: "PASS", michael@0: outerFinally ); michael@0: michael@0: michael@0: }