- Normally, if an uncaught exception is thrown inside the debugged code, the debugger exits
- Catchpoints are the equivalent of breakpoints for exceptions
- 'catch <exception type>' will stop code when given exception type is thrown, allowing you to examine state that caused exception to be thrown
- Watch how this code causes the debugger to exit
#!/usr/local/bin/ruby
class ZebraException < Exception; end
ENV['PATH'].split(/\:/).each do |path_entry|
puts path_entry
raise ZebraException, "crap!"
end
% ruby -rdebug test-exception
Debug.rb
Emacs support available.
test-exception:3:class ZebraException < Exception; end
(rdb:1) n
test-exception:5:ENV['PATH'].split(/\:/).each do |path_entry|
(rdb:1) n
test-exception:6: puts path_entry
(rdb:1) n
/Users/dougb/bin
test-exception:7: raise ZebraException, "crap!"
(rdb:1) n
test-exception:7: `crap!' (ZebraException)
test-exception:7: crap! (ZebraException)
from test-exception:5:in `each'
from test-exception:5
%
- A catchpoint is inserted and now we can stop the exit
% ruby -rdebug test-exception
Debug.rb
Emacs support available.
test-exception:3:class ZebraException < Exception; end
(rdb:1) catch ZebraException
Set catchpoint ZebraException.
(rdb:1) c
/Users/dougb/bin
test-exception:7: `crap!' (ZebraException)
from test-exception:5
test-exception:7: raise ZebraException, "crap!"
(rdb:1) p path_entry
"/Users/dougb/bin"
(rdb:1) n
test-exception:7: crap! (ZebraException)
from test-exception:5:in `each'
from test-exception:5
%