title: How to catch exception from constructor without handling entire the function?
body: <p><em>This question is all about just finding any solution that doesn't carry too much boilerplate code - while this could generate some opinion based solutions - Im really just looking for any solution (wihtout too much boilerplate code)</em> </p>
  
  <p>The following is causing me a bit of headache  - while I can easily fix this, I would like to avoid too much boilerplate code. The following is not legal <a href="/questions/tagged/c%2b%2b" class="post-tag" title="show questions tagged &#39;c++&#39;" rel="tag">c++</a> but shows intent.</p>
  
  <pre><code>char* newBuffer(const char* filename)
  {
      auto fm = try { //&lt;--try is not legal here
          boost::interprocess::file_mapping(filename, boost::interprocess::read_only);
      }
      catch (boost::interprocess::interprocess__exception&amp; e) {
          //report error
          return nullptr;//&lt;--this actually makes matters worse since now we cannot just simply wrap in a simpel lambda or function..
      }
      //rest of function ...
  }
  </code></pre>
  
  <p><a href="https://godbolt.org/z/Ug8quN" rel="nofollow noreferrer">snippet on godbolt</a></p>
  
  <p>I could just move the try at the beginning of the function but that would mean to just <code>try</code> the entire function (bad practice) instead of just <code>try</code>'ing <code>file_mapping</code> constructor.
  How would you solve this conundrum and avoid try-block around the entire function ? less boilerplate code is preferred better.</p>
  
  <p><strong>Any answer should also address the issue with returning of nullptr in case of failure.</strong></p>