Tips for handling uncaught exceptions in Internet Explorer

In both Chrome and Firefox, it is possible to suppress exceptions, but unfortunately, this is not the case with Internet Explorer (IE).

window.addEventListener("error", function errorHandler(event) {
    console.log("exception should be suppressed and not shown in the console");
    event.preventDefault();
});

throw "suppress me";

and

window.onerror = function errorHandler() {
    console.log("exception should be suppressed and not shown in the console");
    return true;
};

throw "suppress me";

You can experiment with these methods

https://jsfiddle.net/9uj4xm3g/4/

https://jsfiddle.net/gv0pvy3b/3/

Any thoughts on this?

UPD:

I forgot to mention what I mean by suppressing. I want to be able to completely hide the SCRIPT5022 message by marking an error as handled.

https://i.sstatic.net/Pvozi.png

As stated in https://msdn.microsoft.com/en-us/library/cc197053.aspx

To suppress the default Windows Internet Explorer error message for the window event, set the returnValue property of the event object to true or simply return true in Microsoft JScript.

However, as you can see, this approach does not resolve errors logged to the console

Answer №1

The issue at hand lies in your method of throwing the exception.

To rectify this, consider implementing the following approach:

throw new Error("custom error message");

You can find more information on this topic here: https://www.example.com/error-handling-best-practices

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The majority of the sliding banner is crafted using 90% HTML and CSS3, with just a touch

I devised a clever script to smoothly slide an image back and forth across the screen using CSS3. Unfortunately, I encountered a problem with CSS animations - they do not support changing the background-image directly. Attempting to overcome this limitatio ...

Reorganize code in JavaScript and TypeScript files using VSCode

Is there a way to efficiently organize the code within a .js / .ts file using Vscode? Specifically, when working inside a Class, my goal is to have static variables at the top, followed by variables, then methods, and so on automatically. I did some resea ...

Obtain the URL value using jQuery and place it inside a <span> element

How can I insert a href value into the span tag like this? <p class="name"> <a download="adja-lo.pdf" title="adja-lo.pdf" href="http://localhost/MatrixDRSnews/apps/Matrix/server/php/files/adja-lo.pdf">adja-lo.pdf</a> </p> ...

Express does not handle get requests to .html files

const express = require('express'); const app = express(); const port = 3000; const bodyPar=require('body-parser'); const session = require('express-session'); const path=require('path'); var user=["Jared","Bill","Ja ...

Ways to transform epoch timestamp to present timestamp?

Is there a way to accurately convert an epoch timestamp in milliseconds to the current timestamp in milliseconds? My Attempt: var currentTime = (resp.timestamp * 1000) + 1980000000; resp.timestamp represents the epoch timestamp I attempted to add 5 ho ...

What is the best way to load a partial in Rails asynchronously with AJAX?

I am currently using the following code to load a partial when I reach the bottom of a div containing a table: $(document).ready(function () { $("#pastGigs").scroll(function () { if (isScrollBottom()) { $('#pastGig ...

Utilize jQuery to create a dynamic image swapping and div showing/hiding feature

I'm having trouble implementing a toggle functionality for an image and another div simultaneously. Currently, when the image is clicked, it switches to display the other div, but clicking again does not switch it back. Can someone please advise on wh ...

Exploring jQuery: Moving between different table cells using traversal techniques

Seeking assistance from experienced jQuery users as I am new to this library and may not be approaching this task correctly. I have a dynamically generated HTML table that is quite extensive. To enhance user experience, I aim to assign navigation function ...

populating a HTML image tag 'src' attribute with data extracted from API javascript code

Hey there! I'm currently working on integrating an image element from the openweatherAPI that corresponds to the weather icon retrieved from the JSON data when a user inputs a city. This means displaying images like scattered clouds or clear skies bas ...

I'm interested in using JavaScript to create a URL for the current page with two additional parameters

Currently, I am utilizing the sharethis plugin within a smarty template. When sharing on Twitter, the link appears as follows: <span class='st_twitter_large' st_via="mediajobscom" st_url="MY URL HERE" displayText='Tweet'> My goa ...

Unable to fetch Rails response through Ajax

Whenever I make a post request from my phonegap app (using ajax in javascript) to my rails server, the post goes through successfully. However, I do not receive any response from the server which ultimately leads to failure. It's puzzling why I'm ...

How can I import a JavaScript file from the assets folder in Nuxt.js?

I have explored multiple methods for importing the JS file, but I am still unable to locate it. Can anyone guide me on how to import a JS file from the assets folder to nuxt.config.js and have it accessible throughout the entire website? nuxt.config.js he ...

Countdown Clock for Displaying Parsing Time in C#

On my aspx page, I have a submit button that triggers the parsing of ".txt" files when clicked. The parsing process generates results stored in tables and then redirects the user to another page. However, the issue at hand is that the parsing operation t ...

Move a component within a container based on the position of the mouse cursor upon entry

Is there a way to make an element slide into a div, but have its starting position vary? <div class="block"> <div class="hover">…</div> </div> If the user enters the div from the left, the element should slide in from the le ...

The hyperlink function is not operational in Gmail attachments

Using an anchor tag to navigate to a specific section within the same page works perfectly when the HTML file is on my local machine. However, when I attach the file in Gmail and open the attachment, it doesn't work. Why is this happening? How can I m ...

Preventing the use of zero as the first character in the text input field

Utilizing AngularJS and jQuery along with Javascript, I have encountered an issue. While the code works perfectly in JSFiddle, it fails to function on a JSP page. $('input#myId').keypress(function(e){ if (this.value.length == 0 &am ...

How do I change the 'CSS Theme' of my website?

With Halloween approaching, I am eager to transform my website's BODY css into a spooky Halloween theme. The challenge is that my .Net pages are Templates. Is there a way for me to ensure that the body class checks for an existing CSS theme override? ...

Tips on how to retrieve a variable from an array in Vue JS

New to Javascript and Vue, I am exploring examples to grasp the fundamental concepts. <template> /*<p v-bind:class="['bold', 'italic', isValid ? 'valid' : 'invalid']">*/ <p v-bind:class= ...

Guide on creating several TypeScript interfaces that share identical type structures

export interface UserFailureResponse { statusCode: number statusMessage: string } export interface UserCreateResponse { statusCode: number statusMessage: string } export interface AuthCheckResponse { statusCode: number statusMessa ...

Encountering RangeError with the Number() function on my express.js server

I'm working with an HTML form that looks like this: <form class="" action="/" method="post"> <input type="text" name="num1" placeholder="First Number"> <input type= ...