Skip to content

Commit

Permalink
Move the proc creation inside AtExitHandlers
Browse files Browse the repository at this point in the history
  • Loading branch information
bew committed Mar 11, 2018
1 parent 7f2b276 commit 33a9c22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/crystal/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ module Crystal
1
end

# This will run after all at_exit handlers, to make sure the user sees the exception if any.
AtExitHandlers.do_last ->(code : Int32) do
ex.try &.inspect_with_backtrace(STDERR)
end
AtExitHandlers.add_exception ex if ex

status = AtExitHandlers.run status
STDOUT.flush
Expand Down
7 changes: 4 additions & 3 deletions src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ module AtExitHandlers
handlers << handler
end

def self.do_last(handler)
# prepend the given handler, to run it last
handlers.unshift handler
def self.add_exception(ex : Exception)
# Prepend a handler for this exception. It will run after all at_exit
# handlers, to make sure the user sees the exception if any.
handlers.unshift ->(status : Int32) { ex.inspect_with_backtrace(STDERR) }
end

def self.run(status)
Expand Down

0 comments on commit 33a9c22

Please sign in to comment.