js/src/tests/ecma_2/Statements/try-004.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_2/Statements/try-004.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 + *  File Name:          try-004.js
    1.12 + *  ECMA Section:
    1.13 + *  Description:        The try statement
    1.14 + *
    1.15 + *  This test has a try with one catch block but no finally.
    1.16 + *
    1.17 + *  Author:             christine@netscape.com
    1.18 + *  Date:               11 August 1998
    1.19 + */
    1.20 +var SECTION = "try-004";
    1.21 +var VERSION = "ECMA_2";
    1.22 +var TITLE   = "The try statement";
    1.23 +
    1.24 +startTest();
    1.25 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.26 +
    1.27 +TryToCatch( "Math.PI", Math.PI );
    1.28 +TryToCatch( "Thrower(5)",   "Caught 5" );
    1.29 +TryToCatch( "Thrower(\"some random exception\")", "Caught some random exception" );
    1.30 +
    1.31 +test();
    1.32 +
    1.33 +function Thrower( v ) {
    1.34 +  throw "Caught " + v;
    1.35 +}
    1.36 +
    1.37 +/**
    1.38 + *  Evaluate a string.  Catch any exceptions thrown.  If no exception is
    1.39 + *  expected, verify the result of the evaluation.  If an exception is
    1.40 + *  expected, verify that we got the right exception.
    1.41 + */
    1.42 +
    1.43 +function TryToCatch( value, expect ) {
    1.44 +  try {
    1.45 +    result = eval( value );
    1.46 +  } catch ( e ) {
    1.47 +    result = e;
    1.48 +  }
    1.49 +
    1.50 +  new TestCase(
    1.51 +    SECTION,
    1.52 +    "eval( " + value +" )",
    1.53 +    expect,
    1.54 +    result );
    1.55 +}
    1.56 +
    1.57 +

mercurial