From: Stefano Crocco Date: 2007-03-12T18:07:23+09:00 Subject: Re: string to int: ruby documentation? Alle luned狸 12 marzo 2007, 7stud 7stud ha scritto: > The docs wrote: > >>Integer( arg ) -> anInteger > >>....If arg is a String > > Gary Wright wrote: > > being raised. If you provide arguments that *don't* meet the > > pre-conditions of a method, well then you may or may not get an > > exception > > but it is really your problem in either case because you violated the > > pre-condition and all bets are off. > > I gave Integer() a string and it threw an exception. A quick look at the documentation has lead me to the following considerations: There *are* some places where documentation about exceptions raised is truly missing (examples: File.read => LoadError if file doesn't exist; File.write => SystemCallError if file isn't open for writing, and, of course Integer()). These methods, in my opinion, need to be better documented. Some situations are implicitly assumed to throw exceptions: - passing a method an argument of a type different from the one required (for example, a string to Fixnum#to_s), raises a TypeError exception - passing a method an argument which is of the correct type, but which doesn't fulfill al the prerequisites (for instance, passing an integer greater than 36 to Fixnum#to_s), raises an ArgumentError exception - a method which should do some parsing (for instance Regexp.new or YAML.load) raises an exception if the string doesn't contain valid code. The kind of exception varies, though (Regexp.new raises a RegexpError while YAML.load raises ArgumentError) Stefano