title: PHP - Wrap a variable block in the same try-catch
body: <p>in my PHP project, I use Guzzle to make a lot of different API requests. In order to handle all exception, each API call is wrapped into a try-catch block. An example:</p>
  
  <pre><code>        try {
              $res = $client-&gt;get($url, [
                  'headers' =&gt; [
                      'Authorization' =&gt; "bearer " . $jwt,
                  ]
              ]);
          } catch (ClientException $clientException) {
              // Do stuff
          } catch (ConnectException $connectException) {
              // Do stuff
          }catch (RequestException $requestException){
              // Do stuff
          }
  </code></pre>
  
  <p>For each request, the exceptiuon handling is the same but the actual execution block differs a lot and can not be simply described by an array of options.</p>
  
  <p>Is there a way to create a function/class able to wrap a custom execution block into the same try-catch handling?</p>
  
  <p>The only options I came up with is to use an interface with a function <code>execution()</code> that is extended by each child and a function <code>run()</code> that has the try-catch blocks and simply calls <code>$this-&gt;execution()</code> inside the execution block. It would work, but I found too verbose the creation of a whole new class for each different API call that is only used in one point of my project.</p>
  
  <p>Is there a better/less verbose solution to avoid code repetition of the same exception handling?</p>