JavaScript

Throw and Catch

function factorial (x) {
        if (x < 0) {
                throw new Error("Negative argument" + x);
        }
        for (var f = 1; x > 1; f *= x, x--);
        return f;
}
try {
        //do stuff
 }
 catch (e) {
         //only one catch, so you might need to:
         switch (e.name) {
         case 'Error':
                 //stuff
                 break;
         default:
                 throw e;
         }
 }
finally {
        //statements that always get executed
}

José M. Vidal .

31 of 65