title: Catching all javascript unhandled exceptions
body: <p>I'm trying to find or figure out a way to display in an alert box all of the unhandled javascript exceptions in an application. I'd want all of this to be done on the client side, without using any server side code. I'm using MVC3 as an environment. </p>
  
  <p>I've been researching for the last few days and haven't found exactly what I'm looking for. </p>
  
  <p>I found 2 ways below that seem like they're almost what I'm looking for, except these ways are set up so that you have to pass a function name into a custom method to print the stack trace of all unhandled exceptions within that one specific function. I'm looking for a way to not have to manually pass a function name to a custom method that prints the stack trace of all of the unhandled exceptions. I'd want these custom method to just 'listen' for all unhandled exceptions within the whole application.</p>
  
  <p><a href="http://eriwen.com/javascript/js-stack-trace/" rel="noreferrer">http://eriwen.com/javascript/js-stack-trace/</a></p>
  
  <p>Also something similar to the previous link:</p>
  
  <p><a href="https://github.com/eriwen/javascript-stacktrace" rel="noreferrer">https://github.com/eriwen/javascript-stacktrace</a></p>
  
  <p>Here's the basic code from the 2nd link above that prints the stack trace of a specified javascript function:</p>
  
  <pre><code>instrumentFunction: function (context, functionName, callback) {
      context = context || window;
      var original = context[functionName];
      context[functionName] = function instrumented() {
          callback.call(this, printStackTrace().slice(4));
          return context[functionName]._instrumented.apply(this, arguments);
      };
      context[functionName]._instrumented = original;
  }
  
  function printStackTrace(options) {
      options = options || {
          guess: true
      };
      var ex = options.e || null,
          guess = !! options.guess;
      var p = new printStackTrace.implementation(),
          result = p.run(ex);
      return (guess) ? p.guessAnonymousFunctions(result) : result;
  }
  </code></pre>
  
  <p>So, to sum this up, do you all know of any way to have some sort of 'listener' to listen for all javascript unhandled exceptions and then print them to the screen in an alert box? </p>
  
  <p>Thanks!
  Jason</p>