“Python Otwórz wiadomość z wyjątkiem” Kod odpowiedzi

Jak wydrukować błąd w próbach oprócz Pythona

try:
  # some code
except Exception as e:
	print("ERROR : "+str(e))
Jenova

Python Drukuj typ wyjątku i wiadomość

# In cases where you need to access exception **type** and message separately
try:
    x = 1/0
except Exception as ex:
  	# In most cases, print(ex) or logging.exception(ex) will do
    # But here we need to format the error message and access its type
    template = "An exception of type '{0}' occurred.\n\tArguments:{1!r}"
    message = template.format(type(ex).__name__, ex.args)
    print(message) 

# The lines above print:
    # An exception of type 'ZeroDivisionError' occurred.
    #    Arguments:('division by zero',)
Muddy Moose

Python Otwórz wiadomość z wyjątkiem

try:
    with open(filepath,'rb') as f:
        con.storbinary('STOR '+ filepath, f)
    logger.info('File successfully uploaded to '+ FTPADDR)
except Exception as e: # work on python 3.x
    logger.error('Failed to upload to ftp: '+ str(e))
Frightened Fox

Python Uzyskaj wyjątek wiadomości

str(your_exception)
Grotesque Guanaco

Odpowiedzi podobne do “Python Otwórz wiadomość z wyjątkiem”

Pytania podobne do “Python Otwórz wiadomość z wyjątkiem”

Więcej pokrewnych odpowiedzi na “Python Otwórz wiadomość z wyjątkiem” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu