“Levante Python” Respostas de código

Exceto como exceção:

>>> def catch():
...     try:
...         asd()
...     except Exception as e:
...         print e.message, e.args
... 
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)
Distinct Dormouse

capturar dados de erro com exceto python

import sys
try:
	S = 1/0 #Create Error
except: # catch *all* exceptions
    e = sys.exc_info()
    print(e) # (Exception Type, Exception Value, TraceBack)

############
#    OR    #
############
try:
	S = 1/0
except ZeroDivisionError as e:
    print(e) # ZeroDivisionError('division by zero')
Cheerful Caracal

Levante Python

#Raises an error made by the user
if something:
    raise Exception('My error!')
Courageous Corncrake

Respostas semelhantes a “Levante Python”

Perguntas semelhantes a “Levante Python”

Mais respostas relacionadas para “Levante Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código