Favorites

JavaScript URIError Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
URIError
JavaScript Errors · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

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

try {
  decodeURIComponent('%');
} catch (err) {
  console.log(err.name, err.message);
}

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.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee