From: Eric Jacoboni Date: 2006-02-09T08:08:30+09:00 Subject: About GetoptLong and exceptions Hi, I try to play with GetoptLong but i don't know how to handle exceptions for this class (i've no found any documentation on this). Here my toy snippet : =-=-=-=-=-=-=-=-=-=-=-=- require 'getoptlong' def print_usage STDERR.puts <<-FIN Usage: #{$0} [--bla | -b ] [--nbre=val | -n val | -c val] [--longueur[=val]�| -l [val] ] fichier1 [fichier2] FIN exit(1) end options = GetoptLong.new( ["--bla", "-b", GetoptLong::NO_ARGUMENT], ["--nbre", "-n", "-c", GetoptLong::REQUIRED_ARGUMENT], ["--longueur", "-l", GetoptLong::OPTIONAL_ARGUMENT]) begin options.each do |opt, arg| case opt when "-b" bla = true when "-n" cpteur = arg when "-l" longueur = (arg ? arg : 10) end # case end # each rescue Exception print_usage end # Now, parsing ARGV (...) =-=-=-=-=-=-=-=-=-=-=-=- So, i expect a command line as "ruby toy.rb -z" would only print the "Usage" message. But here's what i get: toy.rb: invalid option -- z Usage: toy.rb [--bla | -b ] [--nbre=val | -n val | -c val] [--longueur[=val]?| -l [val] ] fichier1 [fichier2] Where the "toy.rb: invalid option -- z" comes from? Unless i have not fully understood the Ruby exception mechanism, it seems that my rescue clause would handle all exceptions, isn't it ? Any clue? -- Eric Jacoboni, ne il y a 1442879654 secondes