4 ms·
Exceptions in Elixir are reserved for situations that are truly exceptional. If IO might fail as a business concern, then we use File.read and pattern match on
by sodapopcan 3y ago
Exceptions in Elixir are reserved for situations that are truly exceptional.
If IO might fail as a business concern, then we use File.read and pattern match on the return type where we can explicitly handle the error case.
Otherwise, if we know a file will always be there and IO is failing for reasons out of our control, that is truly exceptional so we can use File.read! which will throw an exception on failure. In Elixir we generally don't handle this, we just crash and a supervisor brings the process back up.