js异常处理。

<script>
    /*try{
        //抓异常的代码
    }
    catch(e)
    {
        throw  e;//抛出异常
    }
    finally {
        //最后的代码
    }*/

    var txt='你好!'
    try{
    
    
        method(txt);
    }
    catch(e)
    {
    
    
        /*throw  e.message;*/
        //console.log(e.message);
        /*throw  e;*/
        console.log(e.message);//method is not defined
        var error = new Error('请刷新!');
        /* throw  error;*/

    }
    finally {
    
    
        fun(txt);
    }
    function fun(a) {
    
    
        console.log(a);//请刷新!
    }

    console.log(10);//10
</script>

猜你喜欢

转载自blog.csdn.net/weixin_46953330/article/details/118978589
今日推荐