2 * File Name: try-001.js
4 * Description: The try statement
6 * This test contains try, catch, and finally blocks. An exception is
7 * sometimes thrown by a function called from within the try block.
9 * This test doesn't actually make any LiveConnect calls.
12 * Author: christine@netscape.com
13 * Date: 11 August 1998
16 var VERSION = "ECMA_2";
17 var TITLE = "The try statement";
20 writeHeaderToLog( SECTION + " "+ TITLE);
23 var testcases = new Array();
25 var INVALID_JAVA_INTEGER_VALUE = "Invalid value for java.lang.Integer constructor";
27 TryNewJavaInteger( "3.14159", INVALID_JAVA_INTEGER_VALUE );
28 TryNewJavaInteger( NaN, INVALID_JAVA_INTEGER_VALUE );
29 TryNewJavaInteger( 0, 0 );
30 TryNewJavaInteger( -1, -1 );
31 TryNewJavaInteger( 1, 1 );
32 TryNewJavaInteger( Infinity, Infinity );
37 * Check to see if the input is valid for java.lang.Integer. If it is
38 * not valid, throw INVALID_JAVA_INTEGER_VALUE. If input is valid,
43 function newJavaInteger( v ) {
45 if ( Math.floor(value) != value || isNaN(value) ) {
46 throw ( INVALID_JAVA_INTEGER_VALUE );
53 * Call newJavaInteger( value ) from within a try block. Catch any
54 * exception, and store it in result. Verify that we got the right
55 * return value from newJavaInteger in cases in which we do not expect
56 * exceptions, and that we got the exception in cases where an exception
59 function TryNewJavaInteger( value, expect ) {
60 var finalTest = false;
63 result = newJavaInteger( value );
69 testcases[tc++] = new TestCase(
71 "newJavaValue( " + value +" )",
75 testcases[tc++] = new TestCase(
77 "newJavaValue( " + value +" ) hit finally block",