-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix globals, part 12:
reportError()
(#35927)
* move * update * Update index.md * Update index.md --------- Co-authored-by: wbamberg <[email protected]>
- Loading branch information
1 parent
5fc275a
commit 63297de
Showing
13 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: "Window: reportError() method" | ||
short-title: reportError() | ||
slug: Web/API/Window/reportError | ||
page-type: web-api-instance-method | ||
browser-compat: api.reportError | ||
--- | ||
|
||
{{APIRef("DOM")}} | ||
|
||
The **`reportError()`** method of the {{DOMxRef("Window")}} interface may be used to report errors to the console or event handlers of global scopes, emulating an uncaught JavaScript exception. | ||
|
||
This feature is primarily intended for custom event-dispatching or callback-manipulating libraries. | ||
Libraries can use this feature to catch errors in callback code and re-throw them to the top level handler. | ||
This ensures that an exception in one callback will not prevent others from being handled, while at the same time ensuring that stack trace information is still readily available for debugging at the top level. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
reportError(throwable) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `throwable` | ||
- : An error object such as a {{jsxref("TypeError")}}. | ||
|
||
### Return value | ||
|
||
None ({{jsxref("undefined")}}). | ||
|
||
### Exceptions | ||
|
||
- {{jsxref("TypeError")}} | ||
- : The method is called without an error argument. | ||
|
||
## Examples | ||
|
||
Feature test for the method using: | ||
|
||
```js | ||
if (typeof window.reportError === "function") { | ||
// function is defined | ||
} | ||
``` | ||
|
||
The following code shows how you might create and report an error, and how it may be caught using either the `onerror` event handler property or by adding a listener for the `error` event. | ||
Note that the handler assigned to `onerror` must return `true` to stop the event propagating further. | ||
|
||
```js | ||
const newError = new Error("Some error message", "someFile.js", 11); | ||
window.reportError(newError); | ||
|
||
window.onerror = (message, source, lineno, colno, error) => { | ||
console.error(`message: ${error.message}, lineno: ${lineno}`); | ||
return true; | ||
}; | ||
|
||
window.addEventListener("error", (error) => { | ||
console.error(error.filename); | ||
}); | ||
|
||
// Output | ||
// > "message:Some error message, lineno: 11" | ||
// > "someFile.js" | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{DOMxRef("Window")}} | ||
- {{DOMxRef("WorkerGlobalScope.reportError()")}} | ||
- {{DOMxRef("Window/error_event", "error")}} event | ||
- {{DOMxRef("WorkerGlobalScope/error_event", "error")}} event | ||
- {{DOMxRef("HTMLElement/error_event", "error")}} event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters