Skip to content

Instantly share code, notes, and snippets.

@WLSF
Last active November 21, 2020 23:09
Show Gist options
  • Save WLSF/e25338d8267ca4b2176fbdc35081fc10 to your computer and use it in GitHub Desktop.
Save WLSF/e25338d8267ca4b2176fbdc35081fc10 to your computer and use it in GitHub Desktop.
Trying decorators to check if implicit tracing would be a good idea.
defmodule Reports do
use Decorator.Define, [trace: 0]
def trace(body, context) do
quote do
try do
unquote(body)
rescue
e ->
IO.puts("Erro: " <> e.message)
IO.puts("Stack: " <> inspect(__STACKTRACE__))
end
end
end
end
defmodule A do
use Reports
@decorate trace()
def division_by_zero(a), do: a / 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment