-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.txt
47 lines (41 loc) · 1.84 KB
/
text.txt
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
For each of the following variable, identify its type
heights = Array[6, 7, 1, 2, 456]
bool = Array[true, false]
my_name = "Steve"
my_age = 70
is_male = true
my_school = "Digikids"
my_weight = "30 kilograms"
my_height = 1.4
pets = Array["Rex", "Chloe"]
is_sad = false
is_hungry = true
is_tall = "Yes"
counties = Array["Nairobi", "Muranga", "Nakuru"]
Example 1
heights -> Array containing numbers
What is an exception?
An exception represents an error condition in a program.
Exceptions provide a mechanism for stopping the execution of a program.
They function similarly to “break,” in that they cause the instruction
pointer to jump to another location.
Unlike break, the location may be another layer of the program stack.
Unhandled exceptions cause Ruby programs to stop.
When to handle an exception
A simple rule for handling exceptions is to handle only those exceptions
you can do something about.
That’s easy to say, but sometimes difficult to get right. We have a
tendency to want to rescue every exception
that could possibly occur. Because we often don’t know what to
do about an exception, we tend to just log a message
and continue execution. Often this leads to writing extra code to deal
with the failures—code we don’t actually need.
We should handle exceptions only when we can reasonably take some
action to correct the error and allow our program to
continue functioning.
We need to think about three basic categories of exceptional behavior
when writing code: possible, probable, and inevitable.
Possible exceptions
Possible exceptions are theoretically possible, but unlikely to occur in the system. When these kinds of exceptions occur,
it’s typically because the system is truly broken. In this case, the situation is irrecoverable, and
we shouldn’t try to handle the exceptions.