Credo.Check.Readability.PreferImplicitTry (Credo v1.5.0) View Source

This check has a base priority of low and works with any version of Elixir.

Explanation

Prefer using an implicit try rather than explicit try if you try to rescue anything the function does.

For example, this:

def failing_function(first) do
  try do
    to_string(first)
  rescue
    _ -> :rescued
  end
end

Can be rewritten without try as below:

def failing_function(first) do
  to_string(first)
rescue
  _ -> :rescued
end

Like all Readability issues, this one is not a technical concern. The code will behave identical in both ways.

Configuration parameters

There are no specific parameters for this check.

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.