Bullet-proof scripting
 
 
 

When composing MEL scripts, keep the user in mind (even if you are the only user). Make sure that the MEL script considers user errors and handles these errors gracefully.

Think about the errors and boundary conditions that your MEL script might encounter. After checking for an error and finding that it is present, have a reasonable contingency action in your MEL script for that error.

proc burn(string $items[]) {print("Burning all items!\n");}
proc burnSelected() {
 string $selected_s[] = `ls -sl`;
 if (size($selected_s) > 10)
 burn($selected_s);
 else
 print("Need more than ten items to burn.");
}

In this example, if the burnSelected procedure lacks what it needs to perform, it creates an error message rather than failing. It assumes that the burn procedure would fail if given less than ten items. Of course, in this example, the burn procedure would not fail since all it does is print a string.