How to catch DOMException in Chrome?
问题 I get this error: Uncaught (in promise) DOMException: lockOrientation() is not available on this device. code: 9 message: "lockOrientation() is not available on this device." name: "NotSupportedError" when I run the following code in Chrome: try { screen.orientation.lock('portrait'); } catch (error) { // whatever } The fact that the error is being thrown is expected, since Desktop Chrome doesn't support orientation locking. I'd like to catch the error so it doesn't litter the console, but