Corner.Try (corner v0.1.3)
Define macro try!/1
.
try!/1
is similarly as try/1
, but in the rescue
caluses of try!/1
,
the pattern match not just by name, but have the full power of pattern match,
just like in the caluses of case
.
Link to this section Summary
Functions
Enhance the rescue
caluse.
Link to this section Functions
Enhance the rescue
caluse.
try!/1
will traseform the code:
rescue
%ErrorType1{filed: filed} -> filed
%ErrorType2{filed_name: filed} -> filed
to:
rescue
v -> case v do
%MatchError{term: term} -> term
%Error2{field: f} -> v
example
Example
iex> import Corner.Try, only: [try!: 1]
iex> try! do
...> {:ok, 1} = {:bad, 1}
...> rescue
...> %MatchError{term: term} -> term
...> end
{:bad,1}