我想知道是否可以在控制台返回特定错误时运行函数。例如,Google map 有时会返回此错误。
InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lng: not a number
我想做的是在发生此特定错误时发送 alert()
消息。这可能吗?我将如何实现?
最佳答案
您可以使用 try-catch block 。请参阅本页下方:handling a specific error
在你的情况下:
if (e instanceof InvalidValueError) {
...
关于javascript - 返回错误时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33947912/