Exception: Exception
- Defined in:
- lib/core/facets/exception/raised.rb,
lib/core/facets/exception/detail.rb,
lib/core/facets/exception/suppress.rb
Direct Known Subclasses
Class Method Summary (collapse)
-
+ (Boolean) raised?
Does a block raise an a given exception.
-
+ (Object) suppress(*exception_classes)
Supress errors while executing a block, with execptions.
Instance Method Summary (collapse)
-
- (Object) detail
Pretty string output of exception/error object useful for helpful debug messages.
Class Method Details
+ (Boolean) raised?
Does a block raise an a given exception.
5 6 7 8 9 10 11 12 |
# File 'lib/core/facets/exception/raised.rb', line 5 def self.raised? #:yeild: begin yield false rescue self true end end |
+ (Object) suppress(*exception_classes)
Supress errors while executing a block, with execptions.
CREDIT: David Heinemeier Hansson, Thomas Sawyer
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/core/facets/exception/suppress.rb', line 7 def self.suppress(*exception_classes) exception_classes.each do |e| unless e < self raise ArgumentError, "exception #{e} not a subclass of #{self}" end end exception_classes = [self] | exception_classes begin yield rescue Exception => e raise unless exception_classes.any? { |cls| e.kind_of?(cls) } end end |
Instance Method Details
- (Object) detail
Pretty string output of exception/error object useful for helpful debug messages.
Input: The Exception/StandardError object
Output: The pretty printed string
CREDIT: George Moschovitis
14 15 16 |
# File 'lib/core/facets/exception/detail.rb', line 14 def detail return %{#{self.class.name}: #{}\n #{backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]}} end |