Skip to content

Latest commit

 

History

History
88 lines (71 loc) · 2.98 KB

File metadata and controls

88 lines (71 loc) · 2.98 KB
title slug tags browser-compat
URIError
Web/JavaScript/Reference/Global_Objects/URIError
Class
JavaScript
Object
Reference
URIError
javascript.builtins.URIError

{{JSRef}}

The URIError object represents an error when a global URI handling function was used in a wrong way.

URIError is a {{Glossary("serializable object")}}, so it can be cloned with {{domxref("structuredClone()")}} or copied between Workers using {{domxref("Worker.postMessage()", "postMessage()")}}.

Constructor

  • {{jsxref("Global_Objects/URIError/URIError", "URIError()")}}
    • : Creates a new URIError object.

Instance properties

  • {{jsxref("Error.prototype.message", "URIError.prototype.message")}}
    • : Error message. Inherited from {{jsxref("Error")}}.
  • {{jsxref("Error.prototype.name", "URIError.prototype.name")}}
    • : Error name. Inherited from {{jsxref("Error")}}.
  • {{jsxref("Error.prototype.cause", "URIError.prototype.cause")}}
    • : Error cause. Inherited from {{jsxref("Error")}}.
  • {{jsxref("Error.prototype.fileName", "URIError.prototype.fileName")}} {{non-standard_inline}}
    • : Path to file that raised this error. Inherited from {{jsxref("Error")}}.
  • {{jsxref("Error.prototype.lineNumber", "URIError.prototype.lineNumber")}} {{non-standard_inline}}
    • : Line number in file that raised this error. Inherited from {{jsxref("Error")}}.
  • {{jsxref("Error.prototype.columnNumber", "URIError.prototype.columnNumber")}} {{non-standard_inline}}
    • : Column number in line that raised this error. Inherited from {{jsxref("Error")}}.
  • {{jsxref("Error.prototype.stack", "URIError.prototype.stack")}} {{non-standard_inline}}
    • : Stack trace. Inherited from {{jsxref("Error")}}.

Examples

Catching an URIError

try {
  decodeURIComponent('%')
} catch (e) {
  console.log(e instanceof URIError)  // true
  console.log(e.message)              // "malformed URI sequence"
  console.log(e.name)                 // "URIError"
  console.log(e.fileName)             // "Scratchpad/1"
  console.log(e.lineNumber)           // 2
  console.log(e.columnNumber)         // 2
  console.log(e.stack)                // "@Scratchpad/2:2:3\n"
}

Creating an URIError

try {
  throw new URIError('Hello', 'someFile.js', 10)
} catch (e) {
  console.log(e instanceof URIError)  // true
  console.log(e.message)              // "Hello"
  console.log(e.name)                 // "URIError"
  console.log(e.fileName)             // "someFile.js"
  console.log(e.lineNumber)           // 10
  console.log(e.columnNumber)         // 0
  console.log(e.stack)                // "@Scratchpad/2:2:9\n"
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{jsxref("Error")}}
  • {{jsxref("Global_Objects/decodeURI", "decodeURI()")}}
  • {{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent()")}}
  • {{jsxref("Global_Objects/encodeURI", "encodeURI()")}}
  • {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent()")}}