lib/backtrace.rb in backtrace-0.1.0 vs lib/backtrace.rb in backtrace-0.2.0

- old
+ new

@@ -40,6 +40,18 @@ "\n\t", @exp.backtrace.reverse.drop_while { |t| !t.include?(@stop) } .reverse.join("\n\t") ].join end + + def self.exec(swallow: false, log: nil) + yield + rescue StandardError => e + trace = Backtrace.new(e).to_s + if log.nil? + puts trace + else + log.error(trace) + end + raise e unless swallow + end end