Skip to content

Commit

Permalink
Don't early return, always check for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
bew committed Mar 11, 2018
1 parent 17ed1c7 commit c35d1f5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,27 @@ module AtExitHandlers
end

def self.run(status)
return status unless handlers = @@handlers
@@running = true

# Run the registered handlers in reverse order
while handler = handlers.pop?
begin
handler.call status
rescue handler_ex
STDERR.puts "Error running at_exit handler: #{handler_ex}"
status = 1 if status.zero?
if handlers = @@handlers
# Run the registered handlers in reverse order
while handler = handlers.pop?
begin
handler.call status
rescue handler_ex
STDERR.puts "Error running at_exit handler: #{handler_ex}"
status = 1 if status.zero?
end
end
end

# Print the registered exception(s) after all at_exit handlers, to make sure
# the user sees them.
while ex = exceptions.pop?
STDERR.print "Unhandled exception: "
ex.inspect_with_backtrace(STDERR)
if exceptions = @@exceptions
# Print the registered exception(s) after all at_exit handlers, to make sure
# the user sees them.
while ex = exceptions.pop?
STDERR.print "Unhandled exception: "
ex.inspect_with_backtrace(STDERR)
end
end

status
Expand Down

0 comments on commit c35d1f5

Please sign in to comment.