michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Using "try" with "catch" or "finally" statement in a constructor michael@0: * michael@0: * @path ch12/12.14/S12.14_A17.js michael@0: * @description Creating exceptions within constructor michael@0: */ michael@0: michael@0: var i=1; michael@0: function Integer( value, exception ) { michael@0: try{ michael@0: this.value = checkValue( value ); michael@0: if(exception) $ERROR('#'+i+'.1: Must be exception'); michael@0: } michael@0: catch(e){ michael@0: this.value = e.toString(); michael@0: if(!exception) $ERROR('#'+i+'.2: Don`t must be exception'); michael@0: } michael@0: i++; michael@0: } 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: } michael@0: else{ michael@0: return value; michael@0: } michael@0: } michael@0: michael@0: // CHECK#1 michael@0: new Integer(13, false); michael@0: // CHECK#2 michael@0: new Integer(NaN, true); michael@0: // CHECK#3 michael@0: new Integer(0, false); michael@0: // CHECK#4 michael@0: new Integer(Infinity, false); michael@0: // CHECK#5 michael@0: new Integer(-1.23, true); michael@0: // CHECK#6 michael@0: new Integer(Math.LN2, true); michael@0: