Python Forum
Excpetion Handling Getting Error Number - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Excpetion Handling Getting Error Number (/thread-27202.html)



Excpetion Handling Getting Error Number - gw1500se - May-29-2020

I don't know why this is rocket science but I cannot find any way to get just the error number in the exception handler. All the examples show how to get the text but not the error number. The documentation web server seems to be down.

except PermissionError as e:
   print(????error number??????)
Can someone save me from this frustration? TIA.


RE: Excpetion Handling Getting Error Number - buran - May-29-2020

what is "error number"?


RE: Excpetion Handling Getting Error Number - gw1500se - May-29-2020

I thought all exceptions had the same format. Based on your reply I am guessing that is not true. When I print e, I get this:

[Errno 13] Permission denied

Depending on the permission error the number is different but the format is the same. I tried parsing 'e' but it is not just a string so I could not come up with a way to extract it. I tried using various applications of 'split' but the result is always something odd that is not in the printed string (I get things like '[' and ''', etc)


RE: Excpetion Handling Getting Error Number - buran - May-29-2020

that's windowsOS error number, not python error number
Look at https://stackoverflow.com/a/3241538/4046632


RE: Excpetion Handling Getting Error Number - gw1500se - May-29-2020

After some test programming I figured it out 'e' is a PermissionsError class in this case. It contains an attribute named 'errno'. I now understand e will be a specific exception class each of which will have its own attributes. I guess if the documentation web site was up, I'd have been able to determine that. Thanks anyway.