Python: avoid RuntimeError exception?

Tom Tromey tromey@redhat.com
Wed Oct 5 18:18:00 GMT 2011


>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes:

Paul> The Python documentation (Library manual, builtin exceptions chapter)
Paul> implies that RuntimeError is used if nothing better is available,
Paul> i.e., it's sort of deprecated.

Paul> The GDB Python code uses it for most errors, even when a more natural
Paul> exception is also available.  For example, looking up a structure
Paul> field in a gdb.Value object raises RuntimeError if the field is not
Paul> found, instead of the expected KeyError.

Paul> It would be good to tweak some of these to match Python conventions.
Paul> The drawback is that existing checks in existing scripts might need
Paul> updating.

Paul> What's the right answer?

I think we are just stuck with the code as we have shipped it, because I
value compatibility more than using the correct exception.
For new code we can try to do better.

Tom



More information about the Gdb mailing list