Skip to content

Instantly share code, notes, and snippets.

@skorfmann
Created May 8, 2010 13:13
Show Gist options
  • Save skorfmann/394557 to your computer and use it in GitHub Desktop.
Save skorfmann/394557 to your computer and use it in GitHub Desktop.
raise Exception.new
#oder
raise Exception.new("hallo")
#oder auch eigene Exceptions implementieren
class MyTinyException < StandardError
end
raise MyTinyException.new("Super Exception")
#oder aber auch mal ein mehr realistisches Beispiel
class MyFileNotFoundException < StandardError
end
class FileParser
def self.csv(file_path)
raise MyFileNotFoundException.new("File #{file_path}") unless File.exist?(file_path)
#parsing logic
#...
end
end
begin
FileParser.csv("/path/to/not/existing/file")
rescue MyFileNotFoundException => e
puts e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment