Comment on this RCR (edit wiki page) | RCRchive home

RCR 130: Provide a common ancestor for GetoptLong error classes

submitted by anonymous on 2002-12-10 08:06:50


This is a legacy RCR. If this is your RCR, please resubmit it using the new format and process.


Witha little tweaking, the exception mechanism of GetoptLong could be made a lot more convenient,

As I understand it the parsing stage of GetoptLong can throw one of four errors:

The annoyance? They don't have a common yet unique parent. They all inherit from StandardError instead of, ideally, inheriting from something along the lines of a GetoptLong::Error. So, instead of being able to do:
begin
  GetoptLong.new().set_options(
                               [ ... ]
                               ).each ...
rescue GetoptLong::Error
  printHelp()
  exit 1
end
I seem to have to do something like:
begin
  GetoptLong.new().set_options(
                               [ ... ]
                               ).each ...
rescue GetoptLong::AmbigousOption, GetoptLong::NeedlessArgument,
       GetoptLong::MissingArgument, GetoptLong::InvalidOption
  printHelp()
  exit 1
end
That feels a little clumsy. I wonder if there is some reasoning behind this or would it make sense to change GetoptLong so that there is a catch-all parent class for the errors that it can throw?

Vote for this RCR

Strongly opposed [0]
Opposed [0]
Neutral [0]
In favor [3]
Strongly advocate [1]

Change the status of this RCR to:

accepted

rejected

withdrawn


Add comments here

Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog