1 /** 2 * File Name: try-008.js 3 * ECMA Section: 4 * Description: The try statement 5 * 6 * This test has a try block in a constructor. 7 * 8 * 9 * Author: christine (at) netscape.com 10 * Date: 11 August 1998 11 */ 12 var SECTION = "try-008"; 13 var VERSION = "ECMA_2"; 14 var TITLE = "The try statement: try in a constructor"; 15 16 startTest(); 17 writeHeaderToLog( SECTION + " "+ TITLE); 18 19 var tc = 0; 20 var testcases = new Array(); 21 22 function Integer( value, exception ) { 23 try { 24 this.value = checkValue( value ); 25 } catch ( e ) { 26 this.value = e.toString(); 27 } 28 29 testcases[tc++] = new TestCase( 30 SECTION, 31 "Integer( " + value +" )", 32 (exception ? INVALID_INTEGER_VALUE +": " + value : this.value), 33 this.value ); 34 } 35 36 var INVALID_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor"; 37 38 function checkValue( value ) { 39 if ( Math.floor(value) != value || isNaN(value) ) { 40 throw ( INVALID_INTEGER_VALUE +": " + value ); 41 } else { 42 return value; 43 } 44 } 45 46 // add test cases 47 48 new Integer( 3, false ); 49 new Integer( NaN, true ); 50 new Integer( 0, false ); 51 new Integer( Infinity, false ); 52 new Integer( -2.12, true ); 53 new Integer( Math.LN2, true ); 54 55 56 test(); 57