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

605 views

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

In: 10

20 Answers

Anonymous 0 Comments

There are different ways code might not work. The one we’re talking about here is when you break a rule the code has somewhere. Like this function only works with numbers and that one only works with words. If you break the rules, the code tells you it can’t do that by ‘throwing an exception.’ It knows to do that because the person who wrote that bit of code told it to.

You can tell the computer “hey, if this breaks any rules, do this other thing instead.”

If code would cause the whole computer to crash, try/catch might not help.

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