1.4 Errors

There are two main types of errors that you will encounter: Compile time and Runtime Errors.

Syntax Related

A syntax error is an error that occurs when the code is being interpreted. Basically, they are errors while writing the code (if you know Java, syntax errors are roughly equivalent to compile-time errors). For example, Syntax Errors include misspelling something, unknown variable names, type-checking errors, etc.
prnt("Hello") # this would be a compile-time error # someone misspelled 'print' as 'prnt' print("Hello") # this would also result in an error since there's an extra indent
View code on GitHub.


A runtime error is an error that occurs when the code is running. A runtime error will cause your program to shut down right away or not behave the right way. Runtime errors include division by zero, calling methods that don't exist, etc. To avoid these errors, sometimes we use Exception Handling. Other times, we just try to use if/else statements to prevent the error from occurring in the first place. For now though, just try not to call methods that don't exist and/or divide by zero.
print(1 / 0) # this would result in a ZeroDivision error
View code on GitHub.

Previous Section

1.3 Input/Output
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.