title: How to throw custom exception in Optional
body: <p>The orignal code is </p>
  
  <pre><code>if(object==null){
    throw new CustomException(ErrorEnum.OBJECT_NULL)
  }
  </code></pre>
  
  <p>now I want to use <code>Optional</code> to handle <code>NullPointerException</code>.
  Just like this </p>
  
  <pre><code>Optional.ofNullable(object).orElseThrow(()-&gt;{throw new CustomException(ErrorEnum.OBJECT_NULL);}
  </code></pre>
  
  <p>But doing this makes code much longer than original. Maybe I should use the first way to solve the problem?</p>