diff --git a/content/books/things-i-learnt/_index.md b/content/books/things-i-learnt/_index.md index 57c1a5f..c743b28 100644 --- a/content/books/things-i-learnt/_index.md +++ b/content/books/things-i-learnt/_index.md @@ -28,5 +28,6 @@ template = "section-contentless.html" * [Future Thinking Is Future Trashing](future-trashing) * [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) * 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 new file mode 100644 index 0000000..4333fcb --- /dev/null +++ b/content/books/things-i-learnt/crash-it/index.md @@ -0,0 +1,39 @@ ++++ +title = "Things I Learnt The Hard Way - It's Better To Let The Application Crash Than Do Nothing" +date = 2019-06-24 + +[taxonomies] +tags = ["en-au", "books", "things i learnt", "exceptions", "error handling"] ++++ + +Although that sounds weird, it's better to not add any error handling than +silently capturing errors and doing nothing. + + + +For example, a (sadly common) example of Java code: + +```java +try { + something_that_can_raise_exception() +} catch (Exception ex) { + System.out.println(ex); +} +``` + +This does nothing to deal with the exception -- besides printing it, that is. + +The example may be a bit bad, 'cause Java forces capturing exceptions on +functions that throw exceptions and it forces functions to mark themselves as +throwing exceptions if there a `throw` in them. + +But Python doesn't have this restriction and people _still_ try to capture +exceptions for doing absolutely nothing -- and, worse, just keep the execution +going. + +If the language allows it, you should let the application crash due the lack +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") }} diff --git a/content/books/things-i-learnt/interface-changes/index.md b/content/books/things-i-learnt/interface-changes/index.md index 43bd87d..400c047 100644 --- a/content/books/things-i-learnt/interface-changes/index.md +++ b/content/books/things-i-learnt/interface-changes/index.md @@ -32,4 +32,4 @@ you can finally kill the original function. function as deprecated and _add a sleep at the start of the function_, in a way that people using the old function are forced to update.) -{{ chapters(prev_chapter_link="/books/things-i-learnt/boolean-parameters", prev_chapter_title="Don't Use Booleans As Parameters", 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/boolean-parameters", prev_chapter_title="Don't Use Booleans As Parameters", next_chapter_link="/books/things-i-learnt/crash-it", next_chapter_title="It's Better To Let The Application Crash Than Do Nothing") }} 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 9162a12..e39ce08 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/interface-changes", prev_chapter_title="Beware of Interface Changes") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/crash-it", prev_chapter_title="It's Better To Let The Application Crash Than Do Nothing") }}