Add a global exception whitelist (Issue 235)

This commit is contained in:
Conrad Irwin 2011-09-18 09:45:46 +08:00 committed by John Mair
parent 79c4e9890d
commit aaf0cac06b
3 changed files with 8 additions and 1 deletions

View File

@ -55,6 +55,9 @@ class Pry
output.puts "from #{exception.backtrace.first}"
end
# Don't catch these exceptions
DEFAULT_EXCEPTION_WHITELIST = [SystemExit, SignalException]
# The default prompt; includes the target and nesting level
DEFAULT_PROMPT = [
proc { |target_self, nest_level, _|
@ -132,7 +135,7 @@ class Pry
true
# Don't catch signals (particularly not SIGTERM) as these are unlikely to be
# intended for pry itself. We should also make sure that Kernel#exit works.
when SystemExit, SignalException
when *Pry.config.exception_whitelist
false
# All other exceptions will be caught.
else

View File

@ -29,6 +29,9 @@ class Pry
# Pry instances.
attr_accessor :exception_handler
# @return [Array] The classes of exception that will not be caught by Pry.
attr_accessor :exception_whitelist
# Get/Set the Hash that defines Pry hooks used by default by all Pry
# instances.
# @return [Hash] The hooks used by default by all Pry instances.

View File

@ -182,6 +182,7 @@ class Pry
config.print = DEFAULT_PRINT
config.exception_handler = DEFAULT_EXCEPTION_HANDLER
config.exception_window_size = 5
config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST
config.hooks = DEFAULT_HOOKS
config.input_stack = []
config.color = true