Method: Sentry.with_exception_captured

Defined in:
lib/sentry-ruby.rb

.with_exception_captured(**options, &block) ⇒ Object

Takes a block and evaluates it. If the block raised an exception, it reports the exception to Sentry and re-raises it. If the block ran without exception, it returns the evaluation result.

Examples:

Sentry.with_exception_captured do
  1/1 #=> 1 will be returned
end

Sentry.with_exception_captured do
  1/0 #=> ZeroDivisionError will be reported and re-raised
end


443
444
445
446
447
448
# File 'lib/sentry-ruby.rb', line 443

def with_exception_captured(**options, &block)
  yield
rescue Exception => e
  capture_exception(e, **options)
  raise
end