ruby picture

RCR 130: Provide a common ancestor for GetoptLong error classes

Submitted by anonymous (Tue Dec 10 13:12:50 UTC 2002)

Abstract

This is a legacy RCR from Ruby Garden, submitted by anonymous. Matz has declared these RCRs obsolete, and asked that their authors resubmit them in the new format.

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

Problem

(RCR imported from old format)

Proposal

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?

Analysis

(RCR imported from old format)

Implementation

(RCR imported from old format)
ruby picture
Comments Current voting


Strongly opposed 0
Opposed 0
Neutral 0
In favor 0
Strongly advocate 0
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .