I’m writing a library to extend a Ruby gem, specifically selenium-webdriver
. It involves subclassing the Firefox::Driver
class.
In my subclass when should I define/use custom error classes and when should I use the error classes already available to the superclass? E.g.
require 'selenium-webdriver'
module Selenium
module WebDriver
module Firefox
class SpecializedDriver < Driver
class SpecializedError < Error; end # when to do this?
def initialize; end
def foo
raise SpecializedError if some_condition # or e.g. Selenium::WebDriver::Error
end
end
end
end
end
Similarly, with new modules when should I use a custom error class IFO the library’s existing error classes?
A similar question was asked here as a supplementary question, but AFAICT it has never actually been answered.
Are there any conventions that establish when to and when not to
create a new error type?