CKTIS / Python
Exception — base class for ordinary exceptions
Exception is Python’s built-in base class for ordinary exceptions. It lets you define custom error types and catch them together, but does not cover every descendant of BaseException.
Version: Python 3.14; repository image, production runtime not attested
Syntax
Exception(*args)
raise Exception("message")
try:
...
except Exception as exc:
...Exception inherits from BaseException. It is the base class for most built-in exceptions, including ExceptionGroup. By contrast, BaseExceptionGroup inherits directly from BaseException, not from Exception. It can contain instances of a custom BaseException subclass that does not inherit from Exception, even if that subclass has nothing to do with program exit. Custom application exceptions should also inherit from Exception, directly or indirectly.
Exception(*args) creates an object; constructing it alone does not raise an error. Use raise to raise it. Constructor arguments are available in the args tuple; for a single string message, str(exc) returns that message.
except Exception as exc catches Exception and its subclasses, such as ValueError and a custom ValidationError. It does not catch SystemExit, KeyboardInterrupt, or GeneratorExit: they belong to other branches of the BaseException hierarchy.
Prefer handling specific expected types over a broad except Exception. Do not silently ignore unexpected errors; if you cannot handle them, propagate them with a bare raise inside the handler. In the example, a shared handler catches a custom subclass and prints its type, message, and arguments.
Examples
class ValidationError(Exception):
pass
try:
raise ValidationError("invalid value")
except Exception as exc:
print(type(exc).__name__)
print(str(exc))
print(exc.args)
Result
ValidationError
invalid value
('invalid value',)
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.