Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 07964d05b999
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ee730f8de3a9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Aug 29, 2016

  1. Copy the full SHA
    8a0e9cb View commit details

Commits on Aug 30, 2016

  1. Merge pull request #3194 from Sija/patch-1

    Use Exception#message getter instead of @ivar to allow overloading
    bcardiff authored Aug 30, 2016
    Copy the full SHA
    ee730f8 View commit details
Showing with 19 additions and 3 deletions.
  1. +16 −0 spec/std/exception_spec.cr
  2. +3 −3 src/exception.cr
16 changes: 16 additions & 0 deletions spec/std/exception_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "spec"

class FooError < Exception
def message
"#{super || ""} -- bar!"
end
end

describe "Exception" do
it "allows subclassing #message" do
ex = FooError.new("foo?")
ex.message.should eq("foo? -- bar!")
ex.to_s.should eq("foo? -- bar!")
ex.inspect_with_backtrace.should contain("foo? -- bar!")
end
end
6 changes: 3 additions & 3 deletions src/exception.cr
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ class Exception
end

def to_s(io : IO)
io << @message
io << message
end

def inspect_with_backtrace
@@ -167,8 +167,8 @@ class Exception
end

def inspect_with_backtrace(io : IO)
io << @message << " (" << self.class << ")\n"
backtrace.try &.each do |frame|
io << message << " (" << self.class << ")\n"
backtrace?.try &.each do |frame|
io.puts frame
end
io.flush