Any problems handling javascript exception by inserting setTimeout ()?

I have a function that may throw an exception. I would like to expose this exception as if it were thrown (in fact, the same user interface experience, so that it displays as an exception in the browser and console window, any debugging tools). But I do not want the exception to stop the execution of the original function. One solution to this problem is to catch and re-throw an exception, but inside setTimeout (). Thus, it will be called later, but does not interrupt the function due to which it occurred.

Example:

var f = function() {
  try {
    // exception could throw in here somewhere
  } catch (e) {
    setTimeout(
      function() {
        throw e;
      },
      100
    );
  }
}

, ? ( , ?) JavaScript? - ?

: console.log console.error, , console.log , throw e.

+4
2

, ,

console.error(e);

. IE, console , . ,

console = window.console || {error: function(){}};

- , ,

console && console.error(e);

EDIT:

, -

setTimeout(function() { 
    throw new Error('Some meaningful error message. Caused by: ' + e.toString());
}, 0);

, . , , (, , ) .

+4

-, :

var f = function() {
  try {
    // exception could throw in here somewhere
  } catch (e) {
    console.error(e); 
  }
}
+1

All Articles