How To Catch Multiple Exceptions On One Line (Python Recipes)

preview_player
Показать описание
Here's how you can catch multiple exceptions on one line in Python.

▶ Become job-ready with Python:

▶ Follow me on Instagram:
Рекомендации по теме
Комментарии
Автор

well now the next video needs to be on custom exceptions.

DrDeuteron
Автор

This is how I've always done it, I didn't even know you could have multiple except blocks

OnlyXaM
Автор

Thank you. Great video. You could also use "except Exception as e:" to capture all exceptions and repr will let you know what exception it encountered. Awesome.

gokhulmg
Автор

Good I am learning to much from you thanks sir love from pakistan.

MuhammadFaizanMumtaz
Автор

I never really thought about it before, but is it grouping the types like it would a tuple? Would that be a useful language feature in other areas, regardless of whether that's what Python is doing?

anon_y_mousse
Автор

you can also save it in variable:
error = ValueError, TypeError, ZeroDivisionError

Sinke_
Автор

Just a suggestion, f'{number=}'

quintrankid
Автор

One line is short, but it is not a good idea for different exceptions, you need to handle your exception explicity and carefuly, not just throw it in one place,

BohonChina
Автор

How can you encrypt a folder and subfolder with a password in Python and then move them into another folder. Apparently there is no correct explanation on the Internet.

vepman
Автор

Why not just write: except Exception as e:

_mrmark
Автор

I didn't think I've ever been this early. This is fun

murphygreen
welcome to shbcf.ru