Python Forum
Excpetion Handling Getting Error Number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excpetion Handling Getting Error Number
#1
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.
Reply
#2
what is "error number"?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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)
Reply
#4
that's windowsOS error number, not python error number
Look at https://stackoverflow.com/a/3241538/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,263 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Help needed with a "for loop" + error handling tamiri 2 2,490 May-27-2022, 12:21 PM
Last Post: tamiri
  Handling Python Fatal Error richajain1785 7 5,872 Oct-14-2021, 01:34 PM
Last Post: Tails86
  Even number code syntax error MrCeez 1 2,268 May-02-2021, 06:43 PM
Last Post: Larz60+
  Error Handling JarredAwesome 5 2,925 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome
  Error handling using cmd module leifeng 3 2,870 Jun-06-2020, 06:25 PM
Last Post: leifeng
  Error when entering letter/character instead of number/integer helplessnoobb 2 7,052 Jun-22-2019, 07:15 AM
Last Post: ThomasL
  Warning / Error handling in python Prarthana_12 1 5,095 Feb-08-2019, 09:21 PM
Last Post: snippsat
  Help With Error Handling jo15765 6 4,095 Sep-14-2018, 06:27 PM
Last Post: jo15765
  Error when trying to square a number pistacheoowalnuttanker 5 3,813 Jul-20-2018, 02:23 AM
Last Post: pistacheoowalnuttanker

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020