-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.rb
179 lines (140 loc) · 6.26 KB
/
errors.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Analyze the Errors
# I worked on this challenge [by myself].
# I spent [#] hours on this challenge.
# --- error -------------------------------------------------------
cartmans_phrase = "Screw you guys " + "I'm going home."
# This error was analyzed in the README file.
# --- error -------------------------------------------------------
def cartman_hates(thing)
while true
puts "What's there to hate about " + thing +"?"
end
end
# This is a tricky error. The line number may throw you off.
# 1. What is the name of the file with the error?
# errors.rb
# 2. What is the line number where the error occurs?
# The console said that it was line 170, but it was really line 17.
# 3. What is the type of error message?
# Syntax error
# 4. What additional information does the interpreter provide about this type of error?
# It expected a keyword_end
# 5. Where is the error in the code?
# The method needed two ends, one for the method and one for the while loop.
# 6. Why did the interpreter give you this error?
# Because the method never ended until the bottom of the page.
# --- error -------------------------------------------------------
south_park=2
# 1. What is the line number where the error occurs?
# 36
# 2. What is the type of error message?
# NameError
# 3. What additional information does the interpreter provide about this type of error?
# The undefined variable/method is called "south_park"
# 4. Where is the error in the code?
# In main.
# 5. Why did the interpreter give you this error?
# You can't have a variable or method that isn't assigned some kind of value.
# --- error -------------------------------------------------------
def cartman(*)
end
# 1. What is the line number where the error occurs?
# 51
# 2. What is the type of error message?
# NoMethodError
# 3. What additional information does the interpreter provide about this type of error? The undefined method is called cartman
# 4. Where is the error in the code?
# in main
# 5. Why did the interpreter give you this error?
# There should be a def before cartman, and any sort of variable or value in the parentheses.
# --- error -------------------------------------------------------
def cartmans_phrase(x)
puts "I'm not fat; I'm big-boned!"
end
cartmans_phrase("I hate Kyle!")
# 1. What is the line number where the error occurs?
# 66 and 70
# 2. What is the type of error message?
# Argument Error
# 3. What additional information does the interpreter provide about this type of error?
# There was a wrong number of arguments (1 for 0)
# 4. Where is the error in the code?
# In cartmans_phrase
# 5. Why did the interpreter give you this error?
# The program tried to run a method that accepts no arguments, with one argument.
# --- error -------------------------------------------------------
def cartman_says(offensive_message)
puts offensive_message
end
cartman_says("Lick my CENSORED")
# 1. What is the line number where the error occurs?
# 89
# 2. What is the type of error message?
# Argument error
# 3. What additional information does the interpreter provide about this type of error?
# wrong number of arguments, there were 0 for 1
# 4. Where is the error in the code?
# In cartman_says
# 5. Why did the interpreter give you this error?
# It tried to run the method without giving an argument
# --- error -------------------------------------------------------
def cartmans_lie(lie, name)
puts "#{lie}, #{name}!"
end
cartmans_lie('A meteor the size of the earth is about to hit Wyoming!', "Kenny")
# 1. What is the line number where the error occurs?
# 110
# 2. What is the type of error message?
# ArgumentError
# 3. What additional information does the interpreter provide about this type of error?
# wrong number of arguments (1 for 2)
# 4. Where is the error in the code?
# In cartmans_lie
# 5. Why did the interpreter give you this error?
# It only put down one argument, when it required two
# --- error -------------------------------------------------------
"Respect my authoritay!" * 5
# 1. What is the line number where the error occurs?
# 125
# 2. What is the type of error message?
# TypeError
# 3. What additional information does the interpreter provide about this type of error?
# String can't be coerced into Fixnum
# 4. Where is the error in the code?
# In *
# 5. Why did the interpreter give you this error?
# You can't multiply 5 times as string, it has to be the other way around
# --- error -------------------------------------------------------
amount_of_kfc_left = 20*0
# 1. What is the line number where the error occurs?
# 140
# 2. What is the type of error message?
# Zero Division Error
# 3. What additional information does the interpreter provide about this type of error?
# Divided by zero
# 4. Where is the error in the code?
# in /
# 5. Why did the interpreter give you this error?
# You can't divide by zero, it's mathematically impossible.
# --- error -------------------------------------------------------
#require_relative "cartmans_essay.md"
# 1. What is the line number where the error occurs?
# 156
# 2. What is the type of error message?
# Load Error
# 3. What additional information does the interpreter provide about this type of error?
# Cannot load such file
# 4. Where is the error in the code?
# in require_relative
# 5. Why did the interpreter give you this error?
# It tried to load a file that doesn't exist
# --- REFLECTION -------------------------------------------------------
# Write your reflection below as a comment.
#Which error was the most difficult to read?
# The hardest was the first one, because I forgot that while loops need an end as well, and it gave me the wrong line number. I know that it hinted that line number was the key, but I went right past that.
#How did you figure out what the issue with the error was?
#I reviewed the syntax for both methods and while loops, and realized that something was missing.
#Were you able to determine why each error message happened based on the code?
# Yes, the error methods are very specific, and told me exactly what the problem was.
#When you encounter errors in your future code, what process will you follow to help you debug?
# I will make sure to keep calm, and go methodically through the error message. I will find the line, the element, and what issue it ran into. I think that by doing this I will be able to get through most error messages.