Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Exceptions/Ruby/exceptions-1.rb
Normal file
3
Task/Exceptions/Ruby/exceptions-1.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# define an exception
|
||||
class SillyError < Exception
|
||||
end
|
||||
2
Task/Exceptions/Ruby/exceptions-2.rb
Normal file
2
Task/Exceptions/Ruby/exceptions-2.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
class MyInvalidArgument < ArgumentError
|
||||
end
|
||||
11
Task/Exceptions/Ruby/exceptions-3.rb
Normal file
11
Task/Exceptions/Ruby/exceptions-3.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# raise (throw) an exception
|
||||
def spam
|
||||
raise SillyError, 'egg'
|
||||
end
|
||||
|
||||
# rescue (catch) an exception
|
||||
begin
|
||||
spam
|
||||
rescue SillyError => se
|
||||
puts se # writes 'egg' to stdout
|
||||
end
|
||||
15
Task/Exceptions/Ruby/exceptions-4.rb
Normal file
15
Task/Exceptions/Ruby/exceptions-4.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
begin
|
||||
foo
|
||||
rescue ArgumentError => e
|
||||
# rescues a MyInvalidArgument or any other ArgumentError
|
||||
bar
|
||||
rescue => e
|
||||
# rescues a StandardError
|
||||
quack
|
||||
else
|
||||
# runs if no exception occurred
|
||||
quux
|
||||
ensure
|
||||
# always runs
|
||||
baz
|
||||
end
|
||||
2
Task/Exceptions/Ruby/exceptions-5.rb
Normal file
2
Task/Exceptions/Ruby/exceptions-5.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# short way to rescue any StandardError
|
||||
quotient = 1 / 0 rescue "sorry"
|
||||
7
Task/Exceptions/Ruby/exceptions-6.rb
Normal file
7
Task/Exceptions/Ruby/exceptions-6.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def foo
|
||||
throw :done
|
||||
end
|
||||
|
||||
catch :done do
|
||||
foo
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue