Python

try / except / else / finally

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

Përveç except, blloku try mund të ketë else (ekzekutohet vetëm nëse s'pati gabim) dhe finally (ekzekutohet gjithmonë, me apo pa gabim — për pastrim).

EnglishEN

Besides except, a try block can have else (runs only if there was no error) and finally (always runs, error or not — for cleanup).

Si ta mendosh

Si plani i ditës: nëse shkon gjithçka mirë, festo (else); sido që të shkojë, kthehu në shtëpi (finally).

Lexoje në anglisht

Like a day plan: if everything goes well, celebrate (else); however it goes, go home (finally).

Shembull kodipython

try:
    n = int(teksti)
except ValueError: print("S'është numër")
else: print("U lexua:", n)
finally: print("Mbaroi")

Terma të lidhur