Skip to content

Commit

Permalink
Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
skorks committed Apr 9, 2013
1 parent 771d532 commit d727616
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
6 changes: 2 additions & 4 deletions README.md
@@ -1,8 +1,6 @@
# Nesty

Nested exception support for Ruby.

Now, when you rescue an error and raise your own, you don't have to lose track of what actually occured, you can keep/nest the old error in your own and the stacktrace will reflect the cause of the original error.
Now, when you rescue an error and then re-raise your own, you don't have to lose track of what actually occured, you can keep/nest the old error in your own and the stacktrace will reflect the cause of the original error.

## Why Use It?

Expand Down Expand Up @@ -79,7 +77,7 @@ B - message: 'b', backtrace: ['4', '3', '2', '1']
C - message: 'c', backtrace: ['6', '5', '4', '3', '2', '1']
```

If C was not nested and we allowed it to bubble up so that it gets dumped to standard output, we would see the following:
If C was not nested and we allowed it to bubble up so that it gets dumped to standard output, we would see something like the following:

```
c
Expand Down
19 changes: 0 additions & 19 deletions TODO.txt
@@ -1,19 +0,0 @@
- update the readme DONE
- write some examples
- make sure no nested works
- make sure single level of nesting with explicit nested works
- make sure single level with implicit nested works
- make sure 2 levels of nesting with explicit works
- make sure 3 levels of nesting with implicit and explicit mix works correctly
- get the travis stuff working

disadvantages of nestegg
-------------------------
- non-standard looking stack trace
- deep levels of nesting are likely to stuff it up
- need to check if deep levels of nesting will stuff it up



- include the new gem in Escort to replace the nesting stuff that is in there right now
- do a blog post about Ruby nested exceptions
23 changes: 23 additions & 0 deletions examples/complex.rb
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby

require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "nesty"))

class MyError < StandardError
include Nesty::NestedError
end

#just run this to see what get spit out to the console

begin
1/0
rescue => e
begin
raise MyError.new("Number errors will be caught", e)
rescue => e
begin
raise MyError.new("Don't need to let MyError bubble up")
rescue => e
raise MyError.new("Last one for sure!")
end
end
end
11 changes: 11 additions & 0 deletions examples/no_nested.rb
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "nesty"))

class MyError < StandardError
include Nesty::NestedError
end

#just run this to see what get spit out to the console

raise MyError.new("Gotta catch 'em all!")
15 changes: 15 additions & 0 deletions examples/simple.rb
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby

require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "nesty"))

class MyError < StandardError
include Nesty::NestedError
end

#just run this to see what get spit out to the console

begin
1/0
rescue => e
raise MyError.new("Gotta catch 'em all!")
end

0 comments on commit d727616

Please sign in to comment.