try { throw new Error(10,"asdasdasd") } catch (e) {alert(e.message); 警報(e.description)警報(e.number)警報(e.name)拋出新錯誤(10,「asdasdasd」)} sc"/> try { throw new Error(10,"asdasdasd") } catch (e) {alert(e.message); 警報(e.description)警報(e.number)警報(e.name)拋出新錯誤(10,「asdasdasd」)} sc">
<script language="Javascript"> try { throw new Error(10,"asdasdasd") } catch (e) { alert(e.message); alert(e.description) alert(e.number) alert(e.name) throw new Error(10,"asdasdasd") } </script>
try { foo.bar(); } catch (e) { alert(e.name + ": " + e.message); }
EvalError: raised when an error occurs executing code in eval() RangeError: raised when a numeric variable or parameter is outside of its valid range ReferenceError: raised when de-referencing an invalid reference SyntaxError: raised when a syntax error occurs while parsing code in eval() TypeError: raised when a variable or parameter is not a valid type URIError: raised when encodeURI() or decodeURI() are passed invalid parameters
new Error(); new Error("异常信息");
try { throw new Error("Whoops!"); } catch (e) { alert(e.name + ": " + e.message); }
try { foo.bar(); } catch (e) { if (e instanceof EvalError) { alert(e.name + ":" + e.message); } else if (e instanceof RangeError) { alert(e.name + ": " + e.message); } // etc }
try { foo.bar(); } catch (e) { if (browserType != BROWSER_IE) { alert("name: " + e.name + "message: " + e.message + "lineNumber: " + e.lineNumber + "fileName: " + e.fileName + "stack: " + e.stack); } else { alert("name: " + e.name + "errorNumber: " + (e.number & 0xFFFF ) + "message: " + e.message"); } }
try { throw new Date(); // 抛出当前时间对象 } catch (e) { alert(e.toLocaleString()); // 使用本地格式显示当前时间 }
以上是javascript中try catch用法介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!