Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7d4f8fda
Commit
7d4f8fda
authored
Sep 04, 2009
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6777: dont discourage usage of Exception.args or promote usage of Exception.message.
parent
601ee7f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
+14
-17
Doc/tutorial/errors.rst
Doc/tutorial/errors.rst
+14
-17
No files found.
Doc/tutorial/errors.rst
View file @
7d4f8fda
...
@@ -165,14 +165,11 @@ exception type.
...
@@ -165,14 +165,11 @@ exception type.
The except clause may specify a variable after the exception name (or tuple).
The except clause may specify a variable after the exception name (or tuple).
The variable is bound to an exception instance with the arguments stored in
The variable is bound to an exception instance with the arguments stored in
``instance.args``. For convenience, the exception instance defines
``instance.args``. For convenience, the exception instance defines
:meth:`__
getitem__` and :meth:`__str__` so the arguments can be accessed or
:meth:`__
str__` so the arguments can be printed directly without having to
printed directly without having to
reference ``.args``.
reference ``.args``.
But use of ``.args`` is discouraged. Instead, the preferred use is to pass a
One may also instantiate an exception first before raising it and add any
single argument to an exception (which can be a tuple if multiple arguments are
attributes to it as desired. ::
needed) and have it bound to the ``message`` attribute. One may also
instantiate an exception first before raising it and add any attributes to it as
desired. ::
>>> try:
>>> try:
... raise Exception('spam', 'eggs')
... raise Exception('spam', 'eggs')
...
@@ -288,28 +285,28 @@ to create specific exception classes for different error conditions::
...
@@ -288,28 +285,28 @@ to create specific exception classes for different error conditions::
"""Exception raised for errors in the input.
"""Exception raised for errors in the input.
Attributes:
Attributes:
expr
ession
-- input expression in which the error occurred
expr -- input expression in which the error occurred
m
essage
-- explanation of the error
m
sg
-- explanation of the error
"""
"""
def __init__(self, expr
ession, message
):
def __init__(self, expr
, msg
):
self.expr
ession = expression
self.expr
= expr
self.m
essage = message
self.m
sg = msg
class TransitionError(Error):
class TransitionError(Error):
"""Raised when an operation attempts a state transition that's not
"""Raised when an operation attempts a state transition that's not
allowed.
allowed.
Attributes:
Attributes:
prev
ious
-- state at beginning of transition
prev -- state at beginning of transition
next -- attempted new state
next -- attempted new state
m
essage
-- explanation of why the specific transition is not allowed
m
sg
-- explanation of why the specific transition is not allowed
"""
"""
def __init__(self, prev
ious, next, message
):
def __init__(self, prev
, next, msg
):
self.prev
ious = previous
self.prev
= prev
self.next = next
self.next = next
self.m
essage = message
self.m
sg = msg
Most exceptions are defined with names that end in "Error," similar to the
Most exceptions are defined with names that end in "Error," similar to the
naming of the standard exceptions.
naming of the standard exceptions.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment