When do you use each? I consider that I use, if much more, than exceptions. It looks like I caught the exceptions using my "ifs" before I get them. There is an if in all my code.
EAFP: It's easier to ask forgiveness than permission.
The usual Python coding style assumes valid keys or attributes and a catch exception if the assumption is false.
LBYL ( , ), , C.
1
, , , , ! pass, , , !
pass
2
, raise -d, , .
raise
try catch , , , -, , - .., . , , ifs trernary operation.
- , , .
, , , :
- , , , , , .
, , : , , .. :
try... finally
with
, , . , if. python try/except . , , , . .