Created on 2020-03-25 07:27 by tttech-klonner, last changed 2020-03-25 20:21 by rouilj.
|msg6898||Author: [hidden] (tttech-klonner)||Date: 2020-03-25 07:27|
In roundup/exceptions.py there are some exceptions defined which are derived from BaseException. I have a use case where I have to handle those exceptions but I can't because they are using BaseException directly. I would have to catch it with "except BaseException:" which would result in also catching signals like keyboard interrupts or system exits). I would propose to make a common exception class where all other custom Roundup exceptions are derived from. It is also done like this in the roundup/cgi/exceptions.py exceptions. In addition I think we can derive the Roundup base exception class from "Exception" and not "BaseException" as the latter one should be used for built- in exceptions and not user-defined exceptions. roundup/exceptions.py class RoundupException(Exception): pass class Unauthorised(RoundupException): pass class Reject(RoundupException): pass ... If we align on this we could also go though the exceptions in roundup/cgi/exceptions.py and check for those concepts. We can import the RoundupException from roundup/exceptions.py and derive the exceptions for cgi.
|msg6899||Author: [hidden] (rouilj)||Date: 2020-03-25 20:21|
Hi Robert: In message <email@example.com>, Robert Klonner writes: >In roundup/exceptions.py there are some exceptions defined which are derived >from BaseException. I have a use case where I have to handle those exceptions >but I can't because they are using BaseException directly. I would have to >catch it with "except BaseException:" which would result in also catching >signals like keyboard interrupts or system exits). IIRC BaseException was the way it was done in earlier 2.2 pythons. The code base is showing its age. I am interested in your use case. AFAIK you can always: from exceptions import * then use try: ... except (exception1, exception2, exception3 ...): (I may be off on the syntax but you get the idea). Then list each exception you want to catch. Clumsy but workable. However if a new exception is added you will need to change your code 8-(. I see Ralf is already on this ticket. Ralf are you working it? I think (as recommended) a: class RoundupException(Exception): pass and substituting BaseException/Exception in all class definitions with RoundupException makes sense and follows recommended exception hierarchy guidelines. Does anybody see a problem with this? Any cases where this change may break something? I would like to get this in the 2.0 beta release (was planning on starting the release sequence this weekend). Robert I assume you can test it for your use case?
messages: + msg6899