From 9777e8e0ac74c748510e51dc350a1684a3354378 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 30 Aug 2015 14:52:14 -0500 Subject: [PATCH] Add Uncaught Exceptions In Pry as a ruby til. --- README.md | 1 + ruby/uncaught-exceptions-in-pry.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 ruby/uncaught-exceptions-in-pry.md diff --git a/README.md b/README.md index 81ba843..9f757c7 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Rake Only Lists Tasks With Descriptions](ruby/rake-only-lists-tasks-with-descriptions.md) - [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md) - [Summing Collections](ruby/summing-collections.md) +- [Uncaught Exceptions In Pry](ruby/uncaught-exceptions-in-pry.md) - [`undef_method` And The Inheritance Hierarchy](ruby/undef-method-and-the-inheritance-hierarchy.md) ### tmux diff --git a/ruby/uncaught-exceptions-in-pry.md b/ruby/uncaught-exceptions-in-pry.md new file mode 100644 index 0000000..cedf0a3 --- /dev/null +++ b/ruby/uncaught-exceptions-in-pry.md @@ -0,0 +1,21 @@ +# Uncaught Exceptions In Pry + +You are fiddling around with some code in a pry session trying to +familiarize yourself with how it all works. You suddenly execute a statement +that results in an uncaught exception. You'd like to take a closer look at +the exception. Pry makes this easy by exposing the `_ex_` variable which +points to the last uncaught exception. + +Try it out in a pry session: + +```ruby +> class MyError < StandardError; end +=> nil +> def do_stuff; raise MyError, "Something bad happened"; end +=> :do_stuff +> do_stuff +MyError: Something bad happened +from (pry):2:in `do_stuff' +> _ex_ +=> # +```