Blocks try... catch... finally... in JScript 5.
The explanatory for people not familiar with the given design
The design try - catch - finally is intended for interception of mistakes (exceptions). If in the block try any operator there is a mistake, JScript ignores other operators and passes in the block catch where there is a block of processing of exceptions. The last carries out the block finally in which usually carry out certain final actions. Use of an incomplete design - without catch or finally is supposed.
I shall say at once, that there would be no misunderstanding: JScript is JavaScript in interpretation Microsoft, and 5-n the version assumes presence Internet Explorer 5.0 (in 4-th IE only 3-n version JScript).
I do not know as you, and I, how much programmiruju on J [ava] Script dreamed, that in this language would appear at last this design from two words, but there were years, and treasured words and remained preserved and I was have lost any hope as the fifth has left IE...
And, once in the evening, making in the JS Unix (http: // www.chat.ru / ~ junix/) and rummaging simultaneously in interiors of 5-th "probe" my sight has hooked on the next changes familiar " try, catch " and unfamiliar "Error". The vague hope small flickering ogon`kom has lit up in my soul. Cautiously, not giving her to go out I have stretched hands to the keyboard, have typed{collected} try... catch... and in a place annoying "reserved words" have received joyful " presence} is supposed ". It was necessary to see me during that moment (or to hear), I repent: I shouted, that a Gates molodchina. I repent, because a Gates - the bad uncle, has made in the fifth version that it was necessary to make in the first. Well good, all this is wonderful, but necessary to make so, what except for the fifth explorer, other browsers did not notice this block. It is good, that in JScript there is such remarkable thing, as conditional compilation. Having used her it is possible to hide anything you like from extraneous eyes Netscape Navigator and Internet Explorer 4.01 and is lower. Thus, all design looks so (after a semicolon - my comments):
/ * cc_on */; we Include conditional compilation
/ * if (_jscript_version> 4); we Check version JScript
try; the block try
{@end */
Result=eval (expression);; we Do{Make} something useful
/ * if (_jscript_version> 4)
} catch (err); we "Catch" a mistake
{
alert (err.description);; the Message on a mistake
Result = ";
} finally
{
alert (Result);; Finishing actions
};
@end */
/ * cc_off */; we Switch off conditional compilation
Where err - a name of object Error which will be created at occurrence of a mistake, in him parameters of a mistake will be placed. Object Error has three designers and two properties:
err=new Error ();
err=new Error (number);
err=new Error (number, description);
Property (and parameter of the designer) number - numerical value (number{room} of a mistake), property description (as parameter of the designer) - a line, the description of a mistake. Some numerical values and descriptions of mistakes corresponding to them are resulted in the table below:
Number{Room} of a mistake the Description of a mistake
-2146823279 Definition is absent
-2146827282 presence ') ' Is supposed
-2146827273 Uncompleted line constant
-2146827286 Mistake of syntax
-2146827280 presence {Is supposed
-2146827850 Object does not support this property or a method
-2146827843 Command is not supported by object
-2146827859 creation of object by the server of programming of objects Is impossible
-2146828235 File is not found
There is a way programmno to excite exception (to create a mistake) - enough to call the operator throw with object Error created earlier. At interception of a mistake by a design try-catch the created object will be transferred{handed} to the block catch. Examples:
var err=new Error (-10, " Incorrect number ");
throw (err);
throw (new Error (-4, "Mistake"));
Thus JScript has replenished with one more useful design essentially simplifying a life of the programmer.

|