What you're looking for is the javascript:
try{
// code
} catch (err) {
// fail code
}
However, this is not the right way to solve your problem: Exception handling is for handling exceptions, and a scenario that you know can come to pass (such as the user clicking the removeInstance button when there are none to remove) is not an exception.
Don't misunderstand me - putting code inside try/catch is 'good developer manners' (I do it myself all the time), and I strongly encourage you to do the same. Although only for handling exception sprung from code that you think should work just as fine without them.
A better way of solving your particular problem is to remove the minus-button if there are no instances to remove.