vidulaJ
vidulaJ

Reputation: 1270

Catch specific Exception in JavaScript

I know that using following block, it is able to catch an Exception.

try{
    // Code
}catch(err){
    alert(err.message);
}

Say, I want to catch a NumberFormatException. How can I catch a specific Exception using JavaScript?
(I actually want to catch NumberFormatException, InterruptedException, ConnectException which are well defined in Java)

Upvotes: 6

Views: 4630

Answers (1)

simonzack
simonzack

Reputation: 20948

Javascript has no standard way of doing this.

try{
    // Code
}catch(err){
    if(err instanceof SomeException){
        alert(err.message);
    }
}

Firefox has an extension, which I think is nice and should be more standard.

Upvotes: 8

Related Questions