title: Wrap all of your class in try/catch javascript?
body: <p>How to implement a class with method like following?</p>
  
  <pre><code>class ExistingClass {
       function func1() {} // might throw error
       function func2() {} // might throw error
       get try() {
          // Some magic here
          return this; // we need to return this to chain the calls, right? 
       }
  }
  </code></pre>
  
  <p>and can be called like</p>
  
  <pre><code>obj.func1() //might throw an error
  obj.try.func1() // execute func1 in a try/catch
  </code></pre>
  
  <p>basically i would want something like what mochajs has: <code>expect(..).to.not.equal()</code></p>
  
  <p>UPDATE:
  The accepted answer should work, the following is a updated version of it with support for <code>async</code> function</p>
  
  <pre><code>get try() {
      return new Proxy(this, {
  
          // Intercept method getter
          get: function(target, name) {
              if (typeof target[name] === 'function') {
                  if (target[name][Symbol.toStringTag] === 'AsyncFunction') {
                      return async function() {
                          try {
                             await target[name].apply(target, arguments);
                          }
                          catch (e) {}
                      }
                  } else {
                      return function() {
                          try {
                              return target[name].apply(target, arguments)
                          }
                          catch (e) {}
                      }
                  }
              }
              return target[name];
          }
      });
  }
  </code></pre>