I ran the script and it returns "an Illustrator error occured: 1128549443 ('CDLC')". Admittedly I'm not sure where to reference what that means, but I think it probably has to do with either your index number in the loop (if i = 1, then your use of i - 2 returns a value of negative 1) or use of activeDocument.artboards (instead of app.activeDocument.artboards or myDoc.artboards). I tested this with no errors returning:
var myDoc = app.documents[0];
var myABs = myDoc.artboards.length - 1;
for (var i = myABs; i > 0; i--) {
myDoc.artboards.setActiveArtboardIndex(i)
myDoc.artboards.remove();
}
You could also use try and catch statements like so:
// attempt to execute code in a try{ ... } block
try {
for (var i = myABs; i > 0; i--) {
myDoc.artboards.setActiveArtboardIndex(i)
myDoc.artboards.remove();
}
} catch(error){
// catch statement is only in effect if an error occurs:
alert(error);
// if you wanted to bypass an error purposefully, you could use throw or something like:
// } catch(e){return}
};