BaseException.
In a try:
block with an except cause:
clause that mentions a particular class,
that clause handles any exception classes derived from that class (but not exception classes from which it is derived).
Two exception classes that are not related via subclassing are never equivalent, even if they have the same name.
except: aka except BaseExceptions:
# accepts all exception
except Exception as e:
# does not catch ^c ,SystemExit
try:pycom.nvs_get('wake') except Exception as e: print(':'+str(e)+':') # Good only 1 attribute(in this case!) NG print e.message, e.args NG (python 2?) :No matching object for the provided key:Exceptions have an associated value, string or tuple, indicating the detailed cause of the error usually passed as arguments to the exception class's constructor.
User code can raise built-in exceptions, to test an exception handler or to report an error condition
Exception classes can be subclassed to define exceptions with more detail.
Derive new exceptions from the Exception
class or one of its subclasses, not from BaseExceptio n
.
†
__context__
attribute to be
set to the handled exception.
An exception may be handled when an except cause:
or finally:
clause, or
a with:
statement, is used.
This implicit exception context can be supplemented with an explicit cause by using raise new_exc from original_exc
The expression following from
must be an exception or 'None'
.
It will be set as __cause__
on the raised exception.
Setting __cause__
also implicitly sets the __suppress_context__
attribute True
,
so that using raise new_exc from None
effectively replaces the old exception with the new one for display purposes (e.g. converting KeyError to AttributeError),
leaving the old exception available in __context__
for inspection when debugging.
The default traceback display code shows chained exceptions in addition to the traceback for the exception itself.
An explicitly chained exception in __cause__ is always shown when present.
An implicitly chained exception in __context__ is shown only if __cause__ is None and __suppress_context__ is false.
the exception is always shown after any chained exceptions so that the final line of the traceback always shows the last exception that was raised.
BaseException |
base class for built-in exceptions, not meant to be directly inherited by user-defined classes
(use Exception (sic)).
Example showing converting an instance of try: … except SomeException: tb = sys.exc_info()[2] raise OtherException(...).with_traceback(tb) | ||||||||||
KeyboardInterrupt |
User pressed the interrupt key (normally control-c or delete). Inherits from BaseException Raised at unpredictable points and leave the program in an inconsistent state. It is generally best to have KeyboardInterrupt end the program. (See Note on Signal Handlers and Exceptions.)
| ||||||||||
Exception (sic)
Built-in, non-system-exiting exceptions are derived from this class as should user-defined exceptions
| |
ArithmeticError
base class for those built-in exceptions that are raised for various arithmetic errors: | OverflowError, ZeroDivisionError,
unused FloatingPointError.
|
OverflowError
Result of an arithmetic operation is too large to be represented.
Sometimes raised for integers that are outside a required range.
Cannot occur for integers (which would rather raise MemoryError than give up). | Most floating point operations are not checked. |
ZeroDivisionError
Division or modulo is zero. The associated value is a string
| |
BufferError
buffer related operation cannot be performed.
| |
LookupError
key or index used on a mapping or sequence is invalid: | IndexError, KeyError . can be raised directly by
codecs.lookup().
|
AssertionError | assert statement fails. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EOFError |
input() function hits an end-of-file condition (EOF) without reading any data. io.IOBase.read() and io.IOBase.readline() return an empty string on EOF.)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeneratorExit |
generator or
coroutine is closed. It directly inherits from
BaseException instead of Exception since it is technically not an error.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ImportError |
import cannot load a module or the from list has a name that cannot be found.The name and path can be set using keyword-only arguments to the constructor.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subclass
ModuleNotFoundError |
a module could not be located or None is found in
sys.modules .
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AttributeError |
attribute reference or assignment fails. The name and obj attributes can be set using keyword-only arguments to the constructor.
When set they represent the name of the attribute that was attempted to be accessed and the object that was accessed for said attribute.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ValueError |
An operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError .
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
IndexError |
Sequence subscript is out of range. Slice indices are truncated to fall in the allowed range. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TypeError |
Passing arguments of the wrong type (e.g. passing a list when an int is expected) For an index, index is not an integer, See bad index. or An object does not support either attribute references or assignments | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NameError | The unqualified name is not found. The value is an error message that includes the name. The name attribute can be set using a keyword-only argument to the constructor. When set it represents the name of the variable that was attempted to be accessed. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
UnboundLocalError | A reference is made to a local variable in a function or method, but no value has been bound to that variable. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
KeyError | a mapping (dictionary) key is not found in the set of existing keys. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MemoryError |
An operation ran out of memory. This may be recovered from by deleting some objects. The associated value is a string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NotImplementedError |
Derived from RuntimeError . In user defined base classes, abstract methods raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added.
Not used to indicate that an operator or method is not meant to be supported,
in that case either leave the operator / method undefined or, if a subclass, set it to None .
NotImplementedError and NotImplemented are not interchangeable.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OSError([arg]) |
OSError(errno, strerror, filename) OSError(errno, strerror [, filename[, winerror[, filename2]]]) A system function returned an error, including I/O failures such as file not found or disk full. Not for illegal argument types or other incidental errors. The three arguments form the args attribute contains only a 2-tuple of the first two constructor arguments.
The long form of the constructor sets the corresponding attributes which default to 'None'.The constructor may return a subclass of OSError .
When constructing OSError directly or via an alias, and is not inherited when subclassing.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EnvironmentError |
BaseException ┌-- SystemExit ├-- KeyboardInterrupt ├-- GeneratorExit └-- Exception ├-- StopIteration ├-- StopAsyncIteration ├-- ArithmeticError | ├-- FloatingPointError | ├-- OverflowError | '-- ZeroDivisionError ├-- AssertionError ├-- AttributeError ├-- BufferError ├-- EOFError ├-- ImportError | ├-- ModuleNotFoundError ├-- LookupError | ├-- IndexError | '-- KeyError ├-- MemoryError ├-- NameError | '-- UnboundLocalError ├-- OSError | ├-- BlockingIOError | ├-- ChildProcessError | ├-- ConnectionError | | ├-- BrokenPipeError | | ├-- ConnectionAbortedError | | ├-- ConnectionRefusedError | | '-- ConnectionResetError | ├-- FileExistsError | ├-- FileNotFoundError | ├-- InterruptedError | ├-- IsADirectoryError | ├-- NotADirectoryError | ├-- PermissionError | ├-- ProcessLookupError | '-- TimeoutError ├-- ReferenceError ├-- RuntimeError | ├-- NotImplementedError | '-- RecursionError ├-- SyntaxError | ├-- IndentationError | '-- TabError ├-- SystemError ├-- TypeError ├-- ValueError | ├-- UnicodeError | ├-- UnicodeDecodeError | ├-- UnicodeEncodeError | '-- UnicodeTranslateError └-- Warning ├-- DeprecationWarning ├-- PendingDeprecationWarning ├-- RuntimeWarning ├-- SyntaxWarning ├-- UserWarning ├-- FutureWarning ├-- ImportWarning ├-- UnicodeWarning ├-- BytesWarning ├-- EncodingWarning └- ResourceWarning
import errno
>> errno.EIO
5
>> errno.NO_DATA
211
__class__ __name__ errorcode EACCES EADDRINUSE EAGAIN EALREADY EBADF ECONNABORTED ECONNREFUSED ECONNRESET EEXIST EHOSTUNREACH EINPROGRESS EINVAL EIO EISDIR EMSGSIZE ENETDOWN ENOBUFS ENODEV ENOENT ENOMEM ENOTCONN EOPNOTSUPP EPERM ETIMEDOUT ERRMEM ERRBUF ERRTIMEOUT ERRRTE ERRINPROGRESS ERRVAL ERRWOULDBLOCK ERRUSE ERRALREADY ERRISCONN ERRABRT ERRRST ERRCLSD ERRCONN ERRARG ERRIF HOST_NOT_FOUND NO_DATA NO_RECOVERY TRY_AGAIN | |||||||||||||||||||||||||||||||||||||||
EAI
Socket extensions for IPv6 netdb.h SB-BSD-SOCKETS-INTERNAL EAIFAIL EAIMEMORY EAIFAMILY EAISERVICE EAINONAME
| MBEDTLS_ERR_NET_
| Mbed TLS is a C library that implements cryptographic primitives, X.509 certificate manipulation and the SSL/TLS and DTLS protocols EPS_ERR_NO_MEM EPS_ERR_INVALID_ARG
EPS_ERR_INVALID_STATE EPS_ERR_INVALID_SIZE
EPS_ERR_NOT_FOUND EPS_ERR_NOT_SUPPORTED
EPS_ERR_TIMEOUT EPS_ERR_INVALID_RESPONSE
EPS_ERR_INVALID_CRC EPS_ERR_INVALID_VERSION
EPS_ERR_INVALID_MAC
| SOCKET_FAILED CONNECT_FAILED BIND_FAILED LISTEN_FAILED ACCEPT_FAILED RECV_FAILED SEND_FAILED POLL_FAILED UNKNOWN_HOST CONN_RESET BUFFER_TOO_SMALL INVALID_CONTEXT BAD_INPUT_DATA MBEDTLS_ERR_SSL_
|
INVALID_MAC
INVALID_RECORD
CONN_EOF
PEER_VERIFY_FAILED
PEER_CLOSE_NOTIFY
UNKNOWN_CIPHER
NO_CIPHER_CHOSEN
NO_USABLE_CIPHERSUITE
NO_RNG
PRIVATE_KEY_REQUIRED
PK_TYPE_MISMATCH
HELLO_VERIFY_REQUIRED
BAD_HS_CLIENT_HELLO
BAD_HS_SERVER_HELLO
BAD_HS_SERVER_HELLO_DONE
WAITING_SERVER_HELLO_RENEGO
BAD_HS_PROTOCOL_VERSION
BAD_HS_NEW_SESSION_TICKET
CA_CHAIN_REQUIRED
CERTIFICATE_REQUIRED
BAD_HS_CERTIFICATE
BAD_HS_CERTIFICATE_REQUEST
BAD_HS_CERTIFICATE_VERIFY
CERTIFICATE_TOO_LARGE
NO_CLIENT_CERTIFICATE
BAD_HS_SERVER_KEY_EXCHANGE
BAD_HS_CLIENT_KEY_EXCHANGE
BAD_HS_CLIENT_KEY_EXCHANGE_RP
BAD_HS_CLIENT_KEY_EXCHANGE_CS
BAD_HS_CHANGE_CIPHER_SPEC
BAD_HS_FINISHED
ALLOC_FAILED
HW_ACCEL_FAILED
HW_ACCEL_FALLTHROUGH
COMPRESSION_FAILED
SESSION_TICKET_EXPIRED
UNKNOWN_IDENTITY
WANT_READ
WANT_WRITE
CLIENT_RECONNECT
INVALID_VERIFY_HASH
CONTINUE_PROCESSING
ASYNC_IN_PROGRESS
TIMEOUT
COUNTER_WRAPPING
BUFFER_TOO_SMALL
UNEXPECTED_MESSAGE
FATAL_ALERT_MESSAGE
UNEXPECTED_RECORD
NON_FATAL
FEATURE_UNAVAILABLE
BAD_INPUT_DATA
INTERNAL_ERROR
| MBEDTLS_ERR_PK_
|
ALLOC_FAILED
TYPE_MISMATCH
BAD_INPUT_DATA
FILE_IO_ERROR
KEY_INVALID_VERSION
KEY_INVALID_FORMAT
UNKNOWN_PK_ALG
PASSWORD_REQUIRED
PASSWORD_MISMATCH
INVALID_PUBKEY
INVALID_ALG
UNKNOWN_NAMED_CURVE
FEATURE_UNAVAILABLE
SIG_LEN_MISMATCH
HW_ACCEL_FAILED
| |
---|
try:, except, finally:
with exception handling. Calls __enter__(self)
lastly calls __exit__(self)
.
geeksForGeeks