Skip to content

Commit

Permalink
Implement Exception#inspect (#5008)
Browse files Browse the repository at this point in the history
  • 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.