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-008.js michael@0: * ECMA Section: michael@0: * Description: The try statement michael@0: * michael@0: * This test has a try block in a constructor. michael@0: * michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: */ michael@0: var SECTION = "try-008"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "The try statement: try in a constructor"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: function Integer( value, exception ) { michael@0: try { michael@0: this.value = checkValue( value ); michael@0: } catch ( e ) { michael@0: this.value = e.toString(); michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "Integer( " + value +" )", michael@0: (exception ? INVALID_INTEGER_VALUE +": " + value : this.value), michael@0: this.value ); michael@0: } michael@0: michael@0: var INVALID_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor"; michael@0: michael@0: function checkValue( value ) { michael@0: if ( Math.floor(value) != value || isNaN(value) ) { michael@0: throw ( INVALID_INTEGER_VALUE +": " + value ); michael@0: } else { michael@0: return value; michael@0: } michael@0: } michael@0: michael@0: // add test cases michael@0: michael@0: new Integer( 3, false ); michael@0: new Integer( NaN, true ); michael@0: new Integer( 0, false ); michael@0: new Integer( Infinity, false ); michael@0: new Integer( -2.12, true ); michael@0: new Integer( Math.LN2, true ); michael@0: michael@0: michael@0: test();