Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python "except Error as err:"

i just started learning python yesterday and I'm trying to build a program that can navigate my Linux file system. I found this code online which works fine, but I don't understand the exception handling. The format of a try block is

errors = [] 

try
    ...

except OSError as why:
    errors.append((srcname, dstname, str(why)))
except Error as err:
    errors.extend(err.args[0])

I can't find any description of an 'Error' type of exception. I can however find a description of 'OSError' in the python docs. Is 'Error' used to refer to any type of exception?

like image 946
Geoff L Avatar asked Nov 30 '25 15:11

Geoff L


1 Answers

Error is likely to have been defined as a custom class for exceptions. In fact, it's tradition to define Error as the base class for all custom exceptions.

For more information, see this python doc:

like image 51
Adi219 Avatar answered Dec 02 '25 04:12

Adi219



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!