Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
161 views

Python exception for handling invalid argument types

Greetings One small problem that anyone have to tackle with in Python is handling invalid argument types ( without an automatic static type checking tool like Mypy ) One of the best methods for ...
KhodeNima's user avatar
  • 399
3 votes
1 answer
210 views

Catching the timed out Exception raised by the __init__ method of the class ftplib.FTP

Introduction I have written a Python class which uses the module ftplib. In this class I have created a private method called <...
User051209's user avatar
2 votes
2 answers
245 views

User-defined Exceptions for Stack implementation

I am learning about user-defined exceptions in python and I have tried to incorporate them in a basic python implementation of a stack. Objects of Stack class ...
Ganesh Tata's user avatar
7 votes
1 answer
740 views

Wordle guesser, breaking out of loop by raising exception

After many years away from writing in Python, I am getting back into it. Specifically, I am trying to teach myself dataclasses. As an exercise I wrote a Wordle-solving program. I downloaded the ...
Richard D Lawson's user avatar
6 votes
1 answer
213 views

Handling errors in potentially incomplete responses

I am using the library geoip2 to get Geolocation of many IP adderesses ...
Ali Pardhan's user avatar
8 votes
2 answers
4k views

See if a specific resource exists in a Kubernetes namespace

I want to have a function that checks to see if a certain resource (deployment, job, cronjob etc) exist in a namespace. Using the Kubernetes Python client, I can create a boolean function (using ...
user3079474's user avatar
2 votes
1 answer
224 views

Extended exception for network errors in Python

I need a custom exception for network errors that holds a related exception and more than one URL (the first one as the used service has its URL but it indirectly calls other URLs), so I wrote this: <...
LetMeSOThat4U's user avatar
1 vote
1 answer
129 views

Python exception handling class - Getting as much details printed

I'm trying to write a Exception Handling class in Python so that I can re-use. If you have any ideas on how I can improve this to output more detailed information I would appreciate it: ...
Philoxopher's user avatar
2 votes
0 answers
74 views

Extending Exceptions with module-specific prefix, intended for parsing error reporting [closed]

For one of my [WIP] project, I extended the dictionary class a lot with specific handlers, as such I determined that I wanted KeyError and ...
ThorSummoner's user avatar
2 votes
2 answers
2k views

Custom exit with only some exceptions in Python

I want to define an exit code for some exceptions and some exceptions only. I want that the only input is that dictionary with the definition. ...
J L's user avatar
  • 131
2 votes
2 answers
342 views

Python and Exception Handling IOError [closed]

I'm trying to work with exception handling by displaying "No Such File" when the file doesn't exist. I need to use a try statement. ...
CoPoPHP's user avatar
  • 29
23 votes
4 answers
6k views

Is it a good practice to put an exception handler in every method? [closed]

I always add an exception handler when a new method is created, and I don't know if it is a good or bad practice. I thought it may be a bit of an annoyance when viewing the source code. Is it a good ...
poc's user avatar
  • 605
4 votes
1 answer
123 views

Generator expression in combination with StopIteration: kind of a hack? [closed]

The first piece of code should cover the standard expected data. But as you can easily see, the data not always conveys to this standard. The code works great but I wonder if this is thought be a miss-...
LarsVegas's user avatar
  • 203
1 vote
1 answer
5k views

How to handle returned value if an exception happens in a library code

There is a lib code, trying to parse an Element Tree object. If exception happens, it either returns an empty dict of dict or a partially constructed object of such type. In this case, caller needs to ...
user24622's user avatar
3 votes
2 answers
357 views

Raising an assertation error if string is not an email

I created a class EmailParser and check if a supplied string is an email or not with the help of the standard librarie's email module. If the supplied string is not an email I raise an exception. ...
Philipp's user avatar
  • 321