<Ara.T.Howard / noaa.gov> schrieb im Newsbeitrag
news:Pine.LNX.4.60.0408251843470.27498 / harp.ngdc.noaa.gov...
> On Thu, 26 Aug 2004, Yukihiro Matsumoto wrote:
>
> > Hi,
> >
> > In message "Re: POLS - exception comparisons"
> >    on 04/08/25, Jamis Buck <jgb3 / email.byu.edu> writes:
> >
> > |It depends on what you are asking when you want to know if two
> > |exceptions are the same. I can see where, on one hand, you would want
> > |them to be equal if they contain the same information, but on the other
> > |hand, sometimes you might want to know: are these two objects the same
> > |exception that was thrown at some instant x? In that case, it isn't
> > |sufficient to merely check the exception's contents, you have to make
> > |sure they have the same id and are literally the same object.
> >
> > Indeed.  But you can use "equal?" for the same instant.  The point is
> > that which should be the basic comparison (the comparison used most
> > frequently).
> >
> > matz.
>
> IMHO - this is
>
>    "is the error produced by the same condition from the same location in
the
>    code"
>
> eg.
>
>    "is it the same bug/problem"
>
> time is an external actor to a bug (generally) - eg. we'd get the 'same'
error
> at any point in time given the same pre-conditions and therefore they are
> equivalent.  therefore a possible impl is
>
>    self.class == other.class and
>    self.message == other.message and
>    self.backtrace == other.backtrace

You probably don't want the complete backtrace in the comparison.  Regard
this:

def foo(file_name, flag)
  if flag
    io = File.open( file_name )
    # use io
  else
    io = File.open( file_name )
    # use io
  end
end

Now, if the file can't be opened (say, because the directory is missing) the
error will emerge at the same source location (presumable somewhere in File)
and it has the same reason, but backtraces will be different.  So it's
probably better to just compare the first entry of the backtrace.

Kind regards

    robert