Module: Consciously
- Defined in:
- lib/y_support/try.rb
Overview
Provides Try
class, and Object#try method that constructs and calls a Consciously::Try
instance. This #try
method has nothing to do with the error-swallowing #try
method frequently seen elsewhere. On the contrary, our #try
method facilitates raising and ultimately, correcting errors by providing well-formed error messages.
Constructing error messages is labor-intensive. Consciously::Try
allows one to construct verbose error messages with #note
statements inside the block, that act as comments at the same time.
"FooBar".try "to do something" do
note has: "#{size} letters", is: "a #{self.class} instance"
unless include? "Quux"
note "Quux", is: "not a part of it"
try "to append Quux to it" do
self << "Quux"
fail "EPIC FAIL"
end
end
end
Should produce an automatic error message like this: “When trying to do something, FooBar having 6 letters, being a String instance, Quux being not a part of it, RuntimeError occurred: When trying to append Quux to it, RuntimeError occurred: EPIC FAIL”
Defined Under Namespace
Classes: Try