Skip to content

Instantly share code, notes, and snippets.

@expede
Last active September 3, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expede/9d3be8b7fa8855c58459f2752fefbc6b to your computer and use it in GitHub Desktop.
Save expede/9d3be8b7fa8855c58459f2752fefbc6b to your computer and use it in GitHub Desktop.
# Hypothetical rewrite of `File.read`
# Not the lack of a `OtherFile.read!` (with a bang),
# but we get the same effect with the caller via `>>>`
# Success
iex> OtherFile.read("./existing_file.txt")
"I'm a little teapot short and stout ..."
# Error
# Note that this returns an Exception struct as a value
# and *does not raise*
iex> OtherFile.read("./missing.file")
%OtherFile.NotFoundError{
message: "File not found at ./missing.file",
path: "./missing.file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment