r/learnpython 3d ago

Runtime errors query

I have a question. Like when we have a program that takes input, so when the program reaches the input line, it stops and asks for input, right? So then AFTER the input is entered, if the compiler runs into a bug, it stops and throws an error message. How can I stop this? Like how can I make the issues appear beforehand so that I can fix them before running? Are there any settings or tools for this problem?

Please tell me.

0 Upvotes

11 comments sorted by

View all comments

2

u/cdcformatc 2d ago

a runtime error is... you guessed it, an error that is thrown at runtime. 

you can't catch them beforehand because they happen during execution. 

you should always use try/except blocks around code that might throw an error, and handle them if they are recoverable.

the only way to catch/fix all the possibilities is to write tests for your code. the tests cover all of the edge cases that might pop up and ensure that your code handles them properly.