Showing posts with the label Finally

Try, Except, and Finally - Python Handling Errors and Exceptions

When we write source code in Python, there are two types of errors that we encounter. The first type of error is called syntax errors. Syntax errors occur when you violate the syntax of your programming language. If you have syntax errors in your source code, then you cannot compile your program. When you work in a development environment like Visual Studio Code or PyCharm, etc., the IDE itself can detect syntax errors and show them in some way. The second kind of error is runtime error. Runtime error occurs in a compiled program while it is executing. Runtime errors are also known as Exceptions . For instance, the below script will compile and run successfully because the string "8" can be changed to a number. string = "88" number = int(string) print(number) #Output: 88 Let’s look at another example: string = "python" number = int(string) print(number) Running this script will throw a ValueError exception because the string "python" cannot be co