11. errno
11.1. Error codes
from microbit import *
import errno
# print(help(errno))
print(errno.errorcode)
errorcode -- {1: 'EPERM', 2: 'ENOENT', 5: 'EIO',
9: 'EBADF', 11: 'EAGAIN', 12: 'ENOMEM',
13: 'EACCES', 17: 'EEXIST', 19: 'ENODEV',
21: 'EISDIR', 22: 'EINVAL', 95: 'EOPNOTSUPP',
98: 'EADDRINUSE', 103: 'ECONNABORTED',
104: 'ECONNRESET', 105: 'ENOBUFS',
107: 'ENOTCONN', 110: 'ETIMEDOUT',
111: 'ECONNREFUSED', 113: 'EHOSTUNREACH',
114: 'EALREADY', 115: 'EINPROGRESS'}
11.2. File open error
# Imports go at the top
from microbit import *
import errno
try:
with open('non_existent_file.txt', 'r') as file:
content = file.read()
except OSError as e:
if e.errno == errno.ENOENT:
print("Error: File not found.")
else:
print("Error: {}".format(e))
11.3. Error code meanings
EPERM (1): Operation not permitted.
ENOENT (2): No such file or directory.
EIO (5): Input/output error.
EBADF (9): Bad file descriptor.
EAGAIN (11): Try again (resource temporarily unavailable).
ENOMEM (12): Out of memory.
EACCES (13): Permission denied.
EEXIST (17): File exists.
ENODEV (19): No such device.
EISDIR (21): Is a directory.
EINVAL (22): Invalid argument.
EOPNOTSUPP (95): Operation not supported.
EADDRINUSE (98): Address already in use.
ECONNABORTED (103): Software caused connection abort.
ECONNRESET (104): Connection reset by peer.
ENOBUFS (105): No buffer space available.
ENOTCONN (107): Transport endpoint is not connected.
ETIMEDOUT (110): Connection timed out.
ECONNREFUSED (111): Connection refused.
EHOSTUNREACH (113): No route to host.
EALREADY (114): Operation already in progress.
EINPROGRESS (115): Operation now in progress.