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-004.js michael@0: * ECMA Section: michael@0: * Description: The try statement michael@0: * michael@0: * This test has a try with one catch block but no finally. michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "try-004"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "The try statement"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: TryToCatch( "Math.PI", Math.PI ); michael@0: TryToCatch( "Thrower(5)", "Caught 5" ); michael@0: TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" ); michael@0: michael@0: test(); michael@0: michael@0: function Thrower( v ) { michael@0: throw "Caught " + v; michael@0: } michael@0: michael@0: /** michael@0: * Evaluate a string. Catch any exceptions thrown. If no exception is michael@0: * expected, verify the result of the evaluation. If an exception is michael@0: * expected, verify that we got the right exception. michael@0: */ michael@0: michael@0: function TryToCatch( value, expect ) { michael@0: try { michael@0: result = eval( value ); michael@0: } catch ( e ) { michael@0: result = e; michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "eval( " + value +" )", michael@0: expect, michael@0: result ); michael@0: } michael@0: michael@0: