Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f5f2630d
Kaydet (Commit)
f5f2630d
authored
Agu 08, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#3525: 3.0 exception changes in tutorial.
üst
1e3830a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
20 deletions
+16
-20
classes.rst
Doc/tutorial/classes.rst
+1
-1
errors.rst
Doc/tutorial/errors.rst
+15
-19
No files found.
Doc/tutorial/classes.rst
Dosyayı görüntüle @
f5f2630d
...
...
@@ -671,7 +671,7 @@ class or a base class thereof (but not the other way around --- an except clause
listing a derived class is not compatible with a base class). For example, the
following code will print B, C, D in that order::
class B:
class B
(Exception)
:
pass
class C(B):
pass
...
...
Doc/tutorial/errors.rst
Dosyayı görüntüle @
f5f2630d
. _tut-errors:
.
.
_tut-errors:
*********************
Errors and Exceptions
...
...
@@ -131,8 +131,8 @@ the exception (allowing a caller to handle the exception as well)::
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except IOError as
(errno, strerror)
:
print("I/O error
({0}): {1}".format(errno, strerro
r))
except IOError as
err
:
print("I/O error
: {0}".format(er
r))
except ValueError:
print("Could not convert data to an integer.")
except:
...
...
@@ -162,25 +162,21 @@ When an exception occurs, it may have an associated value, also known as the
exception's *argument*. The presence and type of the argument depend on the
exception type.
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 except clause may specify a variable after the exception name
. The
variable is bound to an exception instance with the arguments stored in
``instance.args``. For convenience, the exception instance defines
:meth:`__getitem__` and :meth:`__str__` so the arguments can be accessed or
printed directly without having to reference ``.args``.
But use of ``.args`` is discouraged. Instead, the preferred use is to pass a
single argument to an exception (which can be a tuple if multiple arguments are
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. ::
:meth:`__str__` so the arguments can be printed directly without having to
reference ``.args``. One may also instantiate an exception first before
raising it and add any attributes to it as desired. ::
>>> try:
... raise Exception('spam', 'eggs')
... except Exception as inst:
... print(type(inst)) # the exception instance
... print(inst.args) # arguments stored in .args
... print(inst) # __str__ allows args to be printed directly
... x, y = inst # __getitem__ allows args to be unpacked directly
... print(inst) # __str__ allows args to be printed directly,
... # but may be overridden in exception subclasses
... x, y = inst.args # unpack args
... print('x =', x)
... print('y =', y)
...
...
...
@@ -190,7 +186,7 @@ desired. ::
x = spam
y = eggs
If an exception has a
n argument, it is
printed as the last part ('detail') of
If an exception has a
rguments, they are
printed as the last part ('detail') of
the message for unhandled exceptions.
Exception handlers don't just handle exceptions if they occur immediately in the
...
...
@@ -202,10 +198,10 @@ indirectly) in the try clause. For example::
...
>>> try:
... this_fails()
... except ZeroDivisionError as
detail
:
... print('Handling run-time error:',
detail
)
... except ZeroDivisionError as
err
:
... print('Handling run-time error:',
err
)
...
Handling run-time error: int
eger
division or modulo by zero
Handling run-time error: int division or modulo by zero
.. _tut-raising:
...
...
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