title: Is there a way to add try-catch to every function in Javascript?
body: <p>For error reporting, I would like to insert a try-catch wrapper around the code of every function I have.</p>
  
  <p>So basically I want to replace </p>
  
  <pre><code>function foo(arg){
     bar();
  }
  </code></pre>
  
  <p>...with...</p>
  
  <pre><code>function foo(arg){
      try {
          bar() 
      }
      catch(e){
          customErrorHandler(e)
      }
  }
  </code></pre>
  
  <p>Is there a way to apply this generic try-catch thing to all functions without manually editing all of them? For example by modifying the prototype of the Function object?</p>
  
  <p><strong>EDIT</strong> </p>
  
  <p>Why I want to try-catch all my functions:
  I am building an HTML5 app that I'm publishing on iOS and Android. I can tell from my current rudimentary javascript error reporting that even though the app runs nicely on my own device, errors do occur on some other devices.</p>
  
  <p>My objective is twofold: whenever a javascript error occurs on someone's device...</p>
  
  <ol>
  <li>I want to notify the user that the app may not function perfectly</li>
  <li>I want to know roughly where the error occurred, so I know where to look for the problem</li>
  </ol>