Jeremy Evans wrote:
> We could expand Sequel::Error to store the underlying exception class
> (if any):
>
> class Sequel::Error
> attr_accessor :underlying_exception
> end
>
> That way all Sequel::Errors would have it, and you'd be able to match
> on the underlying exception, plus it wouldn't break assumptions about
> message being a string. What do you think of that?
Actually, I tried that, calling it :wrapped_exception instead, and I
discarded it for some dumb reason (maybe to avoid adding an instance
variable).
Looking at it again, I think you're right. Here's what I've got:
module Sequel
class DatabaseError
attr_reader :wrapped_exception
def initialize ex, bt = ex.backtrace
@wrapped_exception = ex
set_backtrace bt
end
def to_s
"#{wrapped_exception.class}: #{wrapped_exception}"
end
def inspect
"#<#{self.class}: #{wrapped_exception.inspect}>"
end
end
class Database
# Convert the given exception to a DatabaseError, keeping message
# and traceback.
def raise_error(exception, opts={})
if !opts[:classes] || Array(opts[:classes]).any?{|c|
exception.is_a?(c)}
c = (opts[:disconnect] ? DatabaseDisconnectError : DatabaseError)
raise c.new(exception)
else
raise exception
end
end
end
end
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---