diff --git a/content/books/things-i-learnt/_index.md b/content/books/things-i-learnt/_index.md index c743b28..b7692ba 100644 --- a/content/books/things-i-learnt/_index.md +++ b/content/books/things-i-learnt/_index.md @@ -29,5 +29,6 @@ template = "section-contentless.html" * [Don't Use Booleans As Parameters](boolean-parameters) * [Beware of Interface Changes](interface-changes) * [It's Better To Let The Application Crash Than Do Nothing](crash-it) + * [If You Know How To Handle It, Handle It](handle-it) * Community/Teams * [A Language Is Much More Than A Language](languages-are-more) diff --git a/content/books/things-i-learnt/crash-it/index.md b/content/books/things-i-learnt/crash-it/index.md index 4333fcb..3611777 100644 --- a/content/books/things-i-learnt/crash-it/index.md +++ b/content/books/things-i-learnt/crash-it/index.md @@ -36,4 +36,4 @@ of error handling -- as long as you don't have any idea on how to handle it. Then, when they crash, you can think of a way to deal with it, instead of silently capturing it and doing nothing. -{{ chapters(prev_chapter_link="/books/things-i-learnt/interface-changes", prev_chapter_title="Beware of Interface Changes", next_chapter_link="/books/things-i-learnt/languages-are-more", next_chapter_title="A Language Is Much More Than A Language") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/interface-changes", prev_chapter_title="Beware of Interface Changes", next_chapter_link="/books/things-i-learnt/handle-it", next_chapter_title="If You Know How To Handle It, Handle It") }} diff --git a/content/books/things-i-learnt/handle-it/index.md b/content/books/things-i-learnt/handle-it/index.md new file mode 100644 index 0000000..2bc74c5 --- /dev/null +++ b/content/books/things-i-learnt/handle-it/index.md @@ -0,0 +1,30 @@ ++++ +title = "Things I Learnt The Hard Way - If You Know How To Handle It, Handle It" +date = 2019-06-24 + +[taxonomies] +tags = ["en-au", "books", "things i learnt", "exceptions", "error handling"] ++++ + +If you know an error can occur, then you should handle it properly, instead of +ignoring it. + + + +This is the opposite point of [let it crash](/books/things-i-learnt/crash-it): +You're writing some code that you _know_ it can crash in a certain way, what +should you do? Well, the answer is simple: _handle_ it, not _ignore_ it. + +If we go back to the fact that Java will describe every single exception that +can be thrown by a function, you should handle each exception, no excuses. + +If you're using Python, then you should capture the exceptions you know how to +handle, no exceptions -- and tying with the previous point, if you don't know +how to handle them, you should not capture them in the first place. + +But, no matter what language you're using, if you know an error/exception can +occur, _deal with it_. If you have to save the save the content of the user +somewhere else, log it to be reprocessed later or even just show an error +message, do it. + +{{ chapters(prev_chapter_link="/books/things-i-learnt/crash-it", prev_chapter_title="It's Better To Let The Application Crash Than Do Nothing", next_chapter_link="/books/things-i-learnt/languages-are-more", next_chapter_title="A Language Is Much More Than A Language") }} diff --git a/content/books/things-i-learnt/languages-are-more/index.md b/content/books/things-i-learnt/languages-are-more/index.md index e39ce08..7559ef9 100644 --- a/content/books/things-i-learnt/languages-are-more/index.md +++ b/content/books/things-i-learnt/languages-are-more/index.md @@ -39,4 +39,4 @@ surface of what the whole of a language encapsulates and if you ignore the other elements in it, you may find yourself with a cute language in a community that is always fighting and never going forward. -{{ chapters(prev_chapter_link="/books/things-i-learnt/crash-it", prev_chapter_title="It's Better To Let The Application Crash Than Do Nothing") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/handle-it", prev_chapter_title="If You Know How To Handle It, Handle It") }}