File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ # def divider(n1, n2)
2
+ # begin
3
+ # n1 / n2
4
+ # rescue => exception
5
+ # puts exception
6
+ # end
7
+ # end
8
+
9
+ # puts divider(10,0)
10
+
11
+ # but if i pass the 3 digit to the divider then the exception is not working
12
+ # so i also need to check the exception for the main block
13
+
14
+ # begin
15
+ # puts divider(10,0,1)
16
+
17
+ # rescue => exception
18
+ # puts exception
19
+ # puts exception.class
20
+ # puts exception.message
21
+ # puts exception.backtrace
22
+ # end
23
+
24
+
25
+
26
+ #raising own error and customize them
27
+ # def string_validator(input)
28
+ # if input.class != String
29
+ # # raise StandardError, "invalid string: #{input.inspect}"
30
+ # raise StandardError.new("invalid string: #{input.inspect} ")
31
+ # end
32
+ # return input
33
+ # end
34
+ # puts string_validator(9)
35
+ # puts string_validator("i am string")
36
+
37
+
38
+ class StringError < StandardError
39
+ def initialize
40
+ super ( "this input is not a string " )
41
+ end
42
+ end
43
+
44
+ def string_validator ( input )
45
+ if input . class != String
46
+ raise StringError
47
+ end
48
+ return input
49
+ end
50
+ puts string_validator ( 9 )
51
+ # puts string_validator("i am string")
52
+
You can’t perform that action at this time.
0 commit comments