JavaScript URIError Object
A URIError is thrown when the URI encoding or decoding functions, such as decodeURIComponent(), are given a malformed value.
Description
A URIError is thrown by the global URI functions, encodeURI(), encodeURIComponent(), decodeURI() and decodeURIComponent(), when they get a malformed value. The usual cause is decoding a string with a lone % or an incomplete escape sequence, such as '%E0%A4%A'. Wrap decoding of user-supplied text in try...catch.
The encoding functions can also throw it: encodeURIComponent() throws a URIError when a string contains a lone surrogate, a half of a pair of UTF-16 code units that has lost its partner, which can happen when text has been cut in the middle of an emoji. Using str.isWellFormed() or str.toWellFormed() first avoids this.
In modern code, the URL and URLSearchParams objects handle encoding and decoding for you and are more forgiving. They are the safest way to read and build query strings, and you'll rarely see a URIError if you use them.
Creating
new URIError(message)Example
Browser Support
The following information will show you the current browser support for the URIError object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





