title: Use Lambda to wrap methods with same exception handling
body: <p>I have dozens of methods that I want to wrap with the same try/catch handling. I think lambdas can help me out here, but I'm having difficulty figuring out the syntax.</p>
  
  <p>Here's the context of what I'm trying to achieve.</p>
  
  <pre><code>method1(..., result -&gt; method2(result, ...));
  </code></pre>
  
  <p>method2 is a handler for the results of method1. I would like to wrap method2 with a common try/catch statement that's common to a large number of handlers, without having to copy/paste the statement to all handlers.</p>
  
  <p>Note: These are unchecked exceptions.</p>
  
  <p>*edit - Concrete example of what I'm trying to do.</p>
  
  <p>I'm using Vert.x, and they use a common design pattern of Handlers. Here's an example of their SQL interface</p>
  
  <pre><code>query(String sql, Handler&lt;AsyncResult&lt;ResultSet&gt;&gt; resultHandler)
  </code></pre>
  
  <p>Handler is a simple 1 function interface:</p>
  
  <pre><code>void handle(E event)
  </code></pre>
  
  <p>So basically, the query defined in "sql" is executed, and the results are sent to the resultHandler. Here would be an example of this in use:</p>
  
  <pre><code>connection.query("SELECT * from table1", asyncResult -&gt; {
      // do something with results
  }
  </code></pre>
  
  <p>The above uses their documentation's standard coding style. I personally prefer to handle the results in named functions various reasons, so it changes to:</p>
  
  <pre><code>connection.query("SELECT * from table1", asyncResult -&gt; method1(asyncResult));
  
  void method1(AsyncResult&lt;ResultSet&gt; asyncResult) {
      // do something with results
  }
  </code></pre>
  
  <p>I do not have control over the query() interface, so I'm stuck with this pattern. I'm not sure if Tagir's solution will work in this context, but I'll play around with it in the morning.</p>
  
  <p>*edit2 - I should note that I'm trying to wrap method1 in the above example in the exception wrapper, so ideally, I'd add the wrapper call inside the query() call. So what I'm looking for is something like:</p>
  
  <pre><code>connection.query("SELECT * from table1", wrap(asyncResult -&gt; method1(asyncResult)));
  </code></pre>
  
  <p>Obviously, I can't use it that way, because it'll evaluate the original lambda as a parameter, but conceptually, that's where I want the wrapping to be added.</p>