From 6e2ffcd31271c5b43f86d709d54903ed2b9e9f0f Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Thu, 23 Feb 2017 11:32:50 +0000 Subject: [PATCH 1/3] Make error example more readable --- src/loud_errors.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loud_errors.erl b/src/loud_errors.erl index 8eaede9..c679695 100644 --- a/src/loud_errors.erl +++ b/src/loud_errors.erl @@ -12,7 +12,7 @@ bad(WithThis) -> good(WithThis) -> try - something:that(may, WithThis) + something:that(may, fail, WithThis) catch _:Error -> lager:error("Error here: ~p~n" From 71e4f6d7b0ab15033fdda1198fb20c6b5cb49394 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Thu, 23 Feb 2017 11:39:31 +0000 Subject: [PATCH 2/3] Add example of silent error via throw --- src/loud_errors.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/loud_errors.erl b/src/loud_errors.erl index c679695..9f95781 100644 --- a/src/loud_errors.erl +++ b/src/loud_errors.erl @@ -1,8 +1,8 @@ -module(loud_errors). --export([bad/1, good/1]). +-export([bad1/1, bad2/1, good/1]). -bad(WithThis) -> +bad1(WithThis) -> try something:that(may, fail, WithThis) catch @@ -10,6 +10,14 @@ bad(WithThis) -> {error, Error} end. +bad2(WithThis) -> + try + something:that(may, fail, WithThis) + catch + _:Error -> + throw({error, Error}) + end. + good(WithThis) -> try something:that(may, fail, WithThis) From db9dbef8c90c6cfa1767d41c5c40ec416ea29ee5 Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Thu, 23 Feb 2017 11:41:39 +0000 Subject: [PATCH 3/3] Add example of loud error --- src/loud_errors.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/loud_errors.erl b/src/loud_errors.erl index 9f95781..af6455e 100644 --- a/src/loud_errors.erl +++ b/src/loud_errors.erl @@ -1,6 +1,6 @@ -module(loud_errors). --export([bad1/1, bad2/1, good/1]). +-export([bad1/1, bad2/1, good1/1, good2/1]). bad1(WithThis) -> try @@ -18,7 +18,7 @@ bad2(WithThis) -> throw({error, Error}) end. -good(WithThis) -> +good1(WithThis) -> try something:that(may, fail, WithThis) catch @@ -28,3 +28,11 @@ good(WithThis) -> " Stack: ~p", [Error, WithThis, erlang:get_stacktrace()]), {error, Error} end. + +good2(WithThis) -> + try + something:that(may, fail, WithThis) + catch + _:Error -> + exit({error, Error}) + end.