@@ -363,6 +363,24 @@ msgid ""
363363"x = spam\n"
364364"y = eggs"
365365msgstr ""
366+ ">>> try:\n"
367+ "... raise Exception('spam', 'eggs')\n"
368+ "... except Exception as inst:\n"
369+ "... print(type(inst)) # typ wyjątku\n"
370+ "... print(inst.args) # argumenty przechowywane w .args\n"
371+ "... print(inst) # metoda __str__ pozwala na wypisanie args "
372+ "bezpośrednio,\n"
373+ "... # ale jej definicja może być nadpisana w "
374+ "klasach dziedziczących\n"
375+ "... x, y = inst.args # rozpakowanie argumentów\n"
376+ "... print('x =', x)\n"
377+ "... print('y =', y)\n"
378+ "...\n"
379+ "<class 'Exception'>\n"
380+ "('spam', 'eggs')\n"
381+ "('spam', 'eggs')\n"
382+ "x = spam\n"
383+ "y = eggs"
366384
367385msgid ""
368386"The exception's :meth:`~object.__str__` output is printed as the last part "
@@ -423,6 +441,19 @@ msgid ""
423441" print(f\" Unexpected {err=}, {type(err)=}\" )\n"
424442" raise"
425443msgstr ""
444+ "import sys\n"
445+ "\n"
446+ "try:\n"
447+ " f = open('moj_plik.txt')\n"
448+ " s = f.readline()\n"
449+ " i = int(s.strip())\n"
450+ "except OSError as err:\n"
451+ " print(\" Błąd OS:\" , err)\n"
452+ "except ValueError:\n"
453+ " print(\" Nie udało się przekonwertować danych na liczbę całkowitą.\" )\n"
454+ "except Exception as err:\n"
455+ " print(f\" Nieoczekiwany {err=}, {type(err)=}\" )\n"
456+ " raise"
426457
427458msgid ""
428459"The :keyword:`try` ... :keyword:`except` statement has an optional *else "
@@ -445,6 +476,14 @@ msgid ""
445476" print(arg, 'has', len(f.readlines()), 'lines')\n"
446477" f.close()"
447478msgstr ""
479+ "for arg in sys.argv[1:]:\n"
480+ " try:\n"
481+ " f = open(arg, 'r')\n"
482+ " except OSError:\n"
483+ " print('nie mogę otworzyć', arg)\n"
484+ " else:\n"
485+ " print(arg, 'ma', len(f.readlines()), 'linii')\n"
486+ " f.close()"
448487
449488msgid ""
450489"The use of the :keyword:`!else` clause is better than adding additional code "
@@ -478,6 +517,15 @@ msgid ""
478517"...\n"
479518"Handling run-time error: division by zero"
480519msgstr ""
520+ ">>> def this_fails():\n"
521+ "... x = 1/0\n"
522+ "...\n"
523+ ">>> try:\n"
524+ "... this_fails()\n"
525+ "... except ZeroDivisionError as err:\n"
526+ "... print('Błąd w czasie wykonania:', err)\n"
527+ "...\n"
528+ "Błąd w czasie wykonania: division by zero"
481529
482530msgid "Raising Exceptions"
483531msgstr "Rzucanie wyjątków"
@@ -495,6 +543,10 @@ msgid ""
495543" File \" <stdin>\" , line 1, in <module>\n"
496544"NameError: HiThere"
497545msgstr ""
546+ ">>> raise NameError('Cześć!')\n"
547+ "Traceback (most recent call last):\n"
548+ " File \" <stdin>\" , line 1, in <module>\n"
549+ "NameError: Cześć!"
498550
499551msgid ""
500552"The sole argument to :keyword:`raise` indicates the exception to be raised. "
@@ -510,7 +562,7 @@ msgstr ""
510562"zainicjowana przez wywołanie jej konstruktora bez argumentów::"
511563
512564msgid "raise ValueError # shorthand for 'raise ValueError()'"
513- msgstr ""
565+ msgstr "raise ValueError # skrót dla 'raise ValueError()' "
514566
515567msgid ""
516568"If you need to determine whether an exception was raised but don't intend to "
@@ -533,6 +585,16 @@ msgid ""
533585" File \" <stdin>\" , line 2, in <module>\n"
534586"NameError: HiThere"
535587msgstr ""
588+ ">>> try:\n"
589+ "... raise NameError('Cześć!')\n"
590+ "... except NameError:\n"
591+ "... print('Minął mnie wyjątek!')\n"
592+ "... raise\n"
593+ "...\n"
594+ "Minął mnie wyjątek!\n"
595+ "Traceback (most recent call last):\n"
596+ " File \" <stdin>\" , line 2, in <module>\n"
597+ "NameError: Cześć!"
536598
537599msgid "Exception Chaining"
538600msgstr "Łańcuch wyjątków"
@@ -562,6 +624,20 @@ msgid ""
562624" File \" <stdin>\" , line 4, in <module>\n"
563625"RuntimeError: unable to handle error"
564626msgstr ""
627+ ">>> try:\n"
628+ "... open(\" database.sqlite\" )\n"
629+ "... except OSError:\n"
630+ "... raise RuntimeError(\" nie udało się obsłużyć błędu\" )\n"
631+ "...\n"
632+ "Traceback (most recent call last):\n"
633+ " File \" <stdin>\" , line 2, in <module>\n"
634+ "FileNotFoundError: [Errno 2] No such file or directory: 'database.sqlite'\n"
635+ "\n"
636+ "During handling of the above exception, another exception occurred:\n"
637+ "\n"
638+ "Traceback (most recent call last):\n"
639+ " File \" <stdin>\" , line 4, in <module>\n"
640+ "RuntimeError: nie udało się obsłużyć błędu"
565641
566642msgid ""
567643"To indicate that an exception is a direct consequence of another, the :"
@@ -574,6 +650,8 @@ msgid ""
574650"# exc must be exception instance or None.\n"
575651"raise RuntimeError from exc"
576652msgstr ""
653+ "# exc musi być instancją klasy Exception albo mieć wartość None.\n"
654+ "raise RuntimeError from exc"
577655
578656msgid "This can be useful when you are transforming exceptions. For example::"
579657msgstr "Może to być przydatne podczas przekształcania wyjątków. Na przykład::"
@@ -598,6 +676,24 @@ msgid ""
598676" File \" <stdin>\" , line 4, in <module>\n"
599677"RuntimeError: Failed to open database"
600678msgstr ""
679+ ">>> def func():\n"
680+ "... raise ConnectionError\n"
681+ "...\n"
682+ ">>> try:\n"
683+ "... func()\n"
684+ "... except ConnectionError as exc:\n"
685+ "... raise RuntimeError('Nie udało się otworzyć bazy danych') from exc\n"
686+ "...\n"
687+ "Traceback (most recent call last):\n"
688+ " File \" <stdin>\" , line 2, in <module>\n"
689+ " File \" <stdin>\" , line 2, in func\n"
690+ "ConnectionError\n"
691+ "\n"
692+ "The above exception was the direct cause of the following exception:\n"
693+ "\n"
694+ "Traceback (most recent call last):\n"
695+ " File \" <stdin>\" , line 4, in <module>\n"
696+ "RuntimeError: Nie udało się otworzyć bazy danych"
601697
602698msgid ""
603699"It also allows disabling automatic exception chaining using the ``from "
@@ -616,6 +712,14 @@ msgid ""
616712" File \" <stdin>\" , line 4, in <module>\n"
617713"RuntimeError"
618714msgstr ""
715+ ">>> try:\n"
716+ "... open('database.sqlite')\n"
717+ "... except OSError:\n"
718+ "... raise RuntimeError from None\n"
719+ "...\n"
720+ "Traceback (most recent call last):\n"
721+ " File \" <stdin>\" , line 4, in <module>\n"
722+ "RuntimeError"
619723
620724msgid ""
621725"For more information about chaining mechanics, see :ref:`bltin-exceptions`."
0 commit comments