python - Handle a specific exception (say, ENOENT) separately from others -


in python, specific posix error conditions not have separate exception types — distinguished attribute inside of oserror exception object.

let's imagine i'm performing file operation (removing possibly inexistent file on sftp) , want ignore enoent, still handle other error or exception. possible more elegantly following?

try:     action() except e oserror:     if e.errno == errno.enoent:         pass     else:         sophisticated_error_handling(e) except e:     sophisticated_error_handling(e) 

i dislike method because involves repetition.

note: there no x-y problem. "action" library function , cannot told ignore enoent.

next except enter error type!

test = [1, 2, 3, 4, 5, 6, 'aasd']  in range(50):    try:       print(test[i]) except indexerror:    pass 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -