eli5: In programming, how does using “try and except/catch” blocks stop the program from crashing?

639 views

eli5: In programming, how does using “try and except/catch” blocks stop the program from crashing?

In: 10

20 Answers

Anonymous 0 Comments

They don’t, really. Programs can crash in many, many ways that try-catch blocks can’t deal with. Things fundamental to the memory access or physical space it is running, or other things, like hardware, misbehaving.

Think of it the other way, focusing on why programs can choose to halt or not.

Your software is built so that even if it is well behaved, it will choose to halt if some condition happens – a signal is thrown to the top level of the program. The try-catch is a net to prevent some or all of those signals from making it up to the top level and halting the program, letting you handle it in a more sensible way.

This is done because it is easier to design all the halting conditions and then figure out how to handle large swaths of them than it is to design a handling mechanism local to each halting condition, or bake in the message passing for halting conditions explicitly to the calls originating anywhere and of any flavor.

You are viewing 1 out of 20 answers, click here to view all answers.