开发者

Why does my javascript Catch block not execute?

I feel silly asking this, I must be missing something obvious.

My javascript looks as follows...开发者_JAVA百科

function onNewItemClick(event)
{
    alert('ello!');
    try
    {
        var xx = 111/0;
    }
    catch(exc)
    {
        alert('fff');
    }
}

alert('ello!') works like it should, but the alert('fff') in the Catch block never gets called. What am I doing wrong here?


The catch doesn't executes because division by zero doesn't rises an exception, it simply sets you xx variable to Infinity.

To check if a number is finite you can use the isFinite function:

if (!isFinite(xx)) {
  //...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜