Common Error Types Notes Day 2 Flashcards

1
Q

what does SyntaxError mean?

A
A SyntaxError results from incorrectly structuring our code.
# SyntaxError because we need to have a value to assign
my_variable =
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does NameError mean?

A

A NameError results from referring to a variable or method name that has not been defined:

my_variable = 42
p my_variabel # NameError because this name has not been defined previously

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does NoMethodError mean?

A

A NoMethodError results from referring to an undefined method. It is considered a special instance of a NameError:

def say_hello(name)
p “hi “ + name
end

hello(“world”) # NoMethodError because hello is not a defined method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does ArgumentError mean?

A

A ArgumentError results from incorrectly specifying arguments for a method call. Typically this means passing too little or too many arguments:

def say_hello(first_name, last_name)
p “hi “ + first_name + “ “ + last_name
end

say_hello(“world”) # ArgumentError because we gave 1 arg, but say_hello expects 2 args

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does TypeError mean?

A

A TypeError results from performing an operation with incompatible data types:

5 + “spaghetti” # TypeError because we cannot add a Integer and a String together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly