ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Raising Exceptions
    Ruby 2022. 9. 11. 05:02
    # Raising Exceptions #
    
    def format_name(first, last)
        if !(first.instance_of?(String) && last.instance_of?(String))
            raise "arguments must be strings" # custom error message 를 만들고 에러가 뜬 순간 method는 종료된다. raise: this is how we can make exceptions manually.
        end
    
        first.capitalize + " " + last.capitalize
    end
    
    p format_name("grace", "hopper")
    p format_name(42, true)

    raise를 사용하여 오류(예외)를 어떻게 보여주는지 설정 할 수 있다.

Designed by Tistory.