Skip to Content
이펙티브 러스트
book

이펙티브 러스트

by 데이비드 드라이스데일, 남기혁
October 2024
Beginner to intermediate
344 pages
7h 44m
Korean
Hanbit Media, Inc.
Content preview from 이펙티브 러스트
209
3
주요 개념
아이템
18
: 패닉하지 마라
터무니없이 복잡해 보였는데, 그 때문인지 크기가 딱 맞는 플라스틱 덮개에 ‘
DON
T
PANIC
이라는 글귀가 큼직하고 친절하게 인쇄되어 있었다.
더글러스 애덤스
Douglas
Adams
이 아이템의 제목을 좀 더 정확히 표현하면 ‘
panic
!
보다 가급적
Result
를 반환하라’고 할 수
있다. 하지만 패닉 (
panic
!
)하지 마라는 표현이 훨씬 귀에 쏙 들어온다.
러스트의 패닉 메커니즘은 프로그램을 복구할 수 없는 수준의 버그가 발생한 경우를 위해 설계
된 것으로,
panic
!
을 통해 스레드를 종료시키는 것이 디폴트 동작이다. 물론 다른 동작으로 얼
마든지 대체할 수 있다.
특히 예외 시스템을 갖춘 언어 (예: 자바나
C
++ )에서 러스트로 넘어온 사람들은
std
::
panic
::
catch
_
unwind
로 예외를 표현하려는 경향이 있는데, 아마도 콜 스택의 더 높은 곳에서 패닉
을 잡을 수 있는 것처럼 보이기 때문이다.
예를 들어 다음과 같이 잘못된 입력을 받을 때 패닉을 실행하는 함수가 있다.
fn divide(a: i64, b: i64) -> i64 {
if b == 0 {
panic!("Cowardly refusing to divide by zero!");
}
a / b
}
이 함수에 잘못된 입력값을 주고 호출하면 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

이펙티브 타입스크립트

이펙티브 타입스크립트

Dan Vanderkam
파이썬으로 살펴보는 아키텍처 패턴

파이썬으로 살펴보는 아키텍처 패턴

오현석, 해리 퍼시벌, 밥 그레고리

Publisher Resources

ISBN: 9791169212946