• Web APIs
  • Window
  • Instance properties
    1. credentialless Experimental
    2. devicePixelRatio
    3. documentPictureInPicture Experimental
    4. event Deprecated
    5. external Deprecated
    6. fence Experimental
    7. fullScreen Non-standard
    8. innerWidth
    9. launchQueue Experimental
    10. locationbar
    11. mozInnerScreenX Non-standard
    12. mozInnerScreenY Non-standard
    13. navigation Experimental
    14. orientation Deprecated
    15. originAgentCluster Experimental
    16. performance
    17. screenLeft
    18. scrollbars
    19. scrollMaxX Non-standard
    20. scrollMaxY Non-standard
    21. sessionStorage
    22. sharedStorage Experimental
    23. status Deprecated
    24. trustedTypes
    25. atob()
    26. back() Non-standard Deprecated
    27. blur() Deprecated
    28. captureEvents() Deprecated
    29. clearImmediate() Non-standard Deprecated
    30. confirm()
    31. dump() Non-standard
    32. find() Non-standard
    33. forward() Non-standard Deprecated
    34. getDefaultComputedStyle() Non-standard
    35. getScreenDetails() Experimental
    36. moveTo()
    37. prompt()
    38. queryLocalFonts() Experimental
    39. releaseEvents() Deprecated
    40. requestFileSystem() Non-standard Deprecated
    41. scroll()
    42. scrollByLines() Non-standard
    43. scrollByPages() Non-standard
    44. setImmediate() Non-standard Deprecated
    45. setResizable() Non-standard Deprecated
    46. showDirectoryPicker() Experimental
    47. showModalDialog() Non-standard Deprecated
    48. showOpenFilePicker() Experimental
    49. showSaveFilePicker() Experimental
    50. sizeToContent() Non-standard
    51. webkitConvertPointFromNodeToPage() Non-standard Deprecated
    52. webkitConvertPointFromPageToNode() Non-standard Deprecated
  • Events
    1. beforeprint
    2. cut
    3. error
    4. hashchange
    5. messageerror
    6. orientationchange Deprecated
    7. pageswap
    8. resize
    9. scrollsnapchange Experimental
    10. scrollsnapchanging Experimental
    11. unload Deprecated
    12. vrdisplayactivate Non-standard Deprecated
    13. vrdisplayconnect Non-standard Deprecated
    14. vrdisplaydeactivate Non-standard Deprecated
    15. vrdisplaydisconnect Non-standard Deprecated
    16. vrdisplaypresentchange Non-standard Deprecated
  • Inheritance
    1. AbstractRange
    2. Comment
    3. DOMError Deprecated
    4. DOMPoint
    5. Document
    6. Event
    7. MutationRecord
    8. NodeList
    9. Text
    10. TreeWalker
    11. 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
    reportError(throwable)
    

    Parameters

    throwable

    An error object such as a TypeError.

    Return value

    None (undefined).

    Exceptions

    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

    Specification
    HTML
    # runtime-script-errors

    Browser compatibility

    BCD tables only load in the browser

    See also