javascript - Questions about try, catch, throw?
PHP中文网
PHP中文网 2017-05-19 10:31:16
0
4
517
try{
    var num = pompt("请输入5~10");
}
catch(err){
    console.log(err);
    console.log(err + "这里我随便加上一段字符串");
}

In the above code, console.log(err); is output on the console like this: ReferenceError: pompt is not defined at index.html:37, there is a prompt line Number.
Butconsole.log(err "I will add a random string here");The output in the console is like this: ReferenceError: pompt is not definedHere I will add a random string String , if a string is added, no error line number will be prompted. What is the reason for this?

PHP中文网
PHP中文网

认证0级讲师

reply all(4)
Ty80

The first sentence prints an object.

The second sentence prints a string. That is, err.toString() + "I just add a string here"

try{
    var num = pompt("请输入5~10");
}
catch(err){
    console.log(err);
    console.log(err.toString());
}

Non-professional answer, for reference only-. -

漂亮男人

You will know after logging err.toString()

Because err+str, err first calls toString to convert it into a string.

洪涛
try{
    var num = pompt("请输入5~10");
}
catch(err){
    console.log(err);
    console.log(err , "这里我随便加上一段字符串");
} 

It can be like this

刘奇

err is data in the form of an object, and is automatically converted into a string when connected with a plus sign.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template