Errors, files and I/O
Elixir has two ways to say that a call failed: an exception, which unwinds the call, or a tuple the caller has to read. This part shows both, when each one belongs at the boundary of a module, and the try blocks that catch a crash on purpose.
The rest of the part is the outside world: a file read and written, a file read line by line, a folder walked, a path joined, and the input and output a command line program uses.
8.1
Exceptions
raise, defexception, rescue, and the stack trace of a real crash
Open
8.2
ok and error tuples
the two tuples a function returns, the ! version that raises, and the caller that decides
Open
8.3
try, rescue, catch and after
the four blocks, when rescue is the wrong tool, and the part that always runs
Open
8.4
Files and IO
File.read and write, the bang versions, and the error tuple of a missing file
Open
8.5
Paths and directories
Path.join, File.ls, mkdir_p, and the temporary folder a test uses
Open
8.6
IO, stdin and stdout
IO.puts, IO.gets, IO.inspect, and the device each one writes to
Open
8.7
A file line by line
a stream over a file, a line split by hand, and the errors of a bad row
Open
8.8
Raise or return an error
the boundary of a library, and the caller that chooses how to fail
Open