Skip to content

Instantly share code, notes, and snippets.

@ldaniel
Created January 30, 2012 15:28
Show Gist options
  • Select an option

  • Save ldaniel/1704970 to your computer and use it in GitHub Desktop.

Select an option

Save ldaniel/1704970 to your computer and use it in GitHub Desktop.
Tratando erros no Ruby
tarifacao = File.open(arquivo, "w")
begin
# excecoes serao capturadas apos o 'begin'
while data = socket.read(512)
tarifacao.write(data)
end
# Trata alguma excecao
rescue SystemCallError
$stderr.print "Erro de IO: " + $!
opFile.close
File.delete(arquivo)
raise
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment