1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
* File Name: try-006.js
10
* Description: The try statement
12
* Throw an exception from within a With block in a try block. Verify
13
* that any expected exceptions are caught.
15
* Author: christine@netscape.com
16
* Date: 11 August 1998
18
var SECTION = "try-006";
19
var VERSION = "ECMA_2";
20
var TITLE = "The try statement";
23
writeHeaderToLog( SECTION + " "+ TITLE);
26
* This is the "check" function for test objects that will
29
function throwException() {
30
throw EXCEPTION_STRING +": " + this.valueOf();
32
var EXCEPTION_STRING = "Exception thrown:";
35
* This is the "check" function for test objects that do not
38
function noException() {
39
return this.valueOf();
45
TryWith( new TryObject( "hello", throwException, true ));
46
TryWith( new TryObject( "hola", noException, false ));
55
* This is the object that will be the "this" in a with block.
57
function TryObject( value, fun, exception ) {
59
this.exception = exception;
61
this.valueOf = new Function ( "return this.value" );
66
* This function has the try block that has a with block within it.
67
* Test cases are added in this function. Within the with block, the
68
* object's "check" function is called. If the test object's exception
69
* property is true, we expect the result to be the exception value.
70
* If exception is false, then we expect the result to be the value of
73
function TryWith( object ) {
84
"TryWith( " + object.value +" )",
85
(object.exception ? EXCEPTION_STRING +": " + object.valueOf() : object.valueOf()),