Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement Exception#inspect (#5008)
  • Loading branch information
asterite authored and RX14 committed Sep 20, 2017
1 parent 0fdf721 commit 12ed6df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/std/exception_spec.cr
Expand Up @@ -13,4 +13,9 @@ describe "Exception" do
ex.to_s.should eq("foo? -- bar!")
ex.inspect_with_backtrace.should contain("foo? -- bar!")
end

it "inspects" do
ex = FooError.new("foo?")
ex.inspect.should eq("#<FooError:foo? -- bar!>")
end
end
4 changes: 4 additions & 0 deletions src/exception.cr
Expand Up @@ -39,6 +39,10 @@ class Exception
io << message
end

def inspect(io : IO)
io << "#<" << self.class.name << ":" << message << ">"
end

def inspect_with_backtrace
String.build do |io|
inspect_with_backtrace io
Expand Down

0 comments on commit 12ed6df

Please sign in to comment.