ruby의 exception은
begin
코드
rescue => exception
코드
end
와 같은 구조로 이루어진다.
예시
begin
new(ticker: ticker_symbol, name: client.company(ticker_symbol).company_name , last_price: client.price(ticker_symbol)) #Stock.new()
rescue => exception
return nil
end
위와 같은 코드에서 object 생성에 실패했을 경우 nil을 리턴하게 된다.
'ruby on rails' 카테고리의 다른 글
render json: @stock (0) | 2020.11.20 |
---|---|
AJAX in ruby on rails (0) | 2020.11.20 |
secure credentials (0) | 2020.11.20 |
setup and use api-key to get stock data (0) | 2020.11.19 |
devise: configuring view (0) | 2020.11.19 |