title: How to raise an exception for a tensorflow out of memory error?
body: <p>I am running several tensorflow inferences using <code>sess.run()</code> in a loop and it happens that some inferences are too heavy for my GPU.</p>
  
  <p>I get errors like :</p>
  
  <pre><code>2019-05-23 15:37:49.582272: E tensorflow/core/common_runtime/executor.cc:623] 
  Executor failed to create kernel. Resource exhausted: OOM when allocating tensor of shape [306] and type float
  </code></pre>
  
  <p>I would like to be able to catch these specific OutOfMemory errors but not other errors (which may be due to a wrong input format or a corrupted graph.)</p>
  
  <p>Obviously, a structure similar to :</p>
  
  <pre><code>try:
     sess.run(node_output, feed_dict={node_input : value_input})
  except:
      do_outOfMemory_specific_stuff()
  </code></pre>
  
  <p>does not work since other kind of errors will lead to a call to the <code>do_outOfMemory_specific_stuff</code> function.</p>
  
  <p>Any idea how to catch these OutOfMemory errors ?</p>