Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 5956

Catch a Specific OSError Exception in Python 3

$
0
0

In Python 3, how can we catch a specific OSError exception?

My current code catches all OSError, but only OSError: [Errno 12] needs to be caught.

try:    foo()except OSError as e:    print('Caught OSError: [Errno12]')

The full error message is:

Caught OSError: [Errno12] Cannot allocate memory

How can we let Python catch only the Errno12 variant of OSError?


Viewing all articles
Browse latest Browse all 5956

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>