This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Exception | |
| NoMemoryError | |
| ScriptError | |
| LoadError | |
| NotImplementedError | |
| SyntaxError | |
| SignalException | |
| Interrupt | |
| StandardError | |
| ArgumentError |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fatorial(n) | |
| raise "Argumento invalido" if n < 1 | |
| return 1 if n == 1 | |
| n * fatorial(n-1) | |
| end | |
| puts fatorial(5) | |
| puts fatorial(4) | |
| puts fatorial(10) | |
| puts fatorial(-4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fatorial(n) | |
| raise ArgumentError if n < 1 | |
| return 1 if n == 1 | |
| n * fatorial(n-1) | |
| end | |
| puts fatorial(5) | |
| puts fatorial(4) | |
| puts fatorial(10) | |
| puts fatorial(-4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fatorial(n) | |
| raise ArgumentError, "Esperava um argumento >= 1. Mas retornou #{n}", caller if n < 1 | |
| return 1 if n == 1 | |
| n * fatorial(n-1) | |
| end | |
| puts fatorial(-4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fatorial(n) | |
| raise TypeError, "Valor invalido, somente inteiros positivos" unless n.is_a? Integer | |
| raise ArgumentError, "Esperava um argumento >= 1. Mas retornou #{n}", caller if n < 1 | |
| return 1 if n == 1 | |
| n * fatorial(n-1) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "test/unit" | |
| require "fatorial.rb" | |
| class TestLibraryFileName < Test::Unit::TestCase | |
| def test_simples_cases | |
| assert_equal(120, fatorial(5)) | |
| assert_equal(6, fatorial(3)) | |
| end | |
| def test_negative_numbers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin | |
| #algum código | |
| rescue Exception => e | |
| #código da manipualação da exceção vem aqui, qualquer exceção levantada pelo código acima, cai aqui. | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def simple(n) | |
| raise ArgumentError, "Argumento Invalido" if n < 0 | |
| end | |
| begin | |
| simple(-4) | |
| rescue Exception => e | |
| puts "#{e.class}: #{e.message}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def simple(n) | |
| raise ArgumentError, "Argumento Invalido" if n < 0 | |
| end | |
| begin | |
| simple(-4) | |
| rescue Exception => e | |
| puts "Dentro do Rescue" | |
| puts "#{e.class}: #{e.message}" | |
| puts $! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin | |
| x = fatorial("f") | |
| rescue ArgumentError => e | |
| puts "Numero >= que 1 eh preciso" | |
| rescue TypeError => e | |
| puts "Tente com intiero" | |
| end |