Type of Errors

Learn about common types of programming mistakes in Ruby, and tips for avoiding them.

Programmers (whether new or experienced) encounter code errors every day. We do not expect you to get the exercises right on the first go. We can all learn from mistakes.

There are three types of errors in Ruby, as shown in the illustration below:

Let's go over each of these error types.

Syntax error

Ruby checks the syntax of code before running it. If there are syntax errors in code, the error messages are usually quite helpful for identifying the error.

The following are some common examples of syntax errors:

Typo

It's normal to make typing mistakes when writing code. For example, in the code below, instead of else in line 5, we typed elwe.

Press + to interact
check = true
if (check)
puts "Pass"
elwe
puts "Fail"
end

When we run the code above, we get an error message that tells us elwe is undefined (don’t worry if this does not make ...