티스토리 뷰
728x90
반응형
Swift 6 에서 'Typed throws' 를 사용할 수 있다.
- Swift Proposal: SE-0413
- WWDC 24 > What’s new in Swift
[1] 개념
AS IS
기존의 에러 처리 방식이다.
catch 블럭에 전달되는 에러는 type erased 되기 때문에
이런 식으로 구체 타입 체크를 했다.
이런 방식을 'UnTyped throws' 라고 한다.
TO BE
이제 'Typed throws' 방식도 지원된다!
이렇게 function 이 throw 할 에러의 구체타입을 지정할 수 있다. (하나의 구체 타입만 사용한다면)
그럼 type erasure 가 안되고
catch 블럭으로 들어오는 에러는 구체타입이다.
[2] 실습
[3] 참고
1)
API 에서 typed throws 를 사용하면 구체 에러 타입을 지정하기 때문에 API 발전에 제약이 생긴다.
그래서 에러타입을 변경할 수 있는 유연성을 유지하고 싶으면 Untyped throws 를 계속 쓰는 게 좋다.
(public API 보다 internal 레벨에서 typed throws 를 쓰는 게 좋다.)
2)
- Untyped throws는 any Error 유형의 typed throws와 같다.
- non-throwing function 은 Never 유형의 typed throw 와 같다.
반응형
'🍏 > Swift' 카테고리의 다른 글
[Swift] @unchecked, @preconcurrency, @retroactive (9) | 2024.11.06 |
---|---|
[Swift] Noncopyable (~Copyable) (3) | 2024.10.26 |
[Swift] AsyncStream (1) | 2024.08.24 |
[Swift] @TaskLocal (0) | 2024.08.23 |
[Swift] @dynamicCallable 유용한 예제 모음 (4) | 2024.03.16 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 장고 URL querystring
- Sketch 누끼
- cocoapod
- flutter 앱 출시
- Flutter Clipboard
- Flutter Spacer
- ribs
- SerializerMethodField
- flutter dynamic link
- 플러터 얼럿
- DRF APIException
- drf custom error
- Flutter 로딩
- flutter build mode
- Django Firebase Cloud Messaging
- flutter deep link
- METAL
- Django Heroku Scheduler
- Flutter Text Gradient
- Python Type Hint
- 플러터 싱글톤
- 장고 Custom Management Command
- 구글 Geocoding API
- Watch App for iOS App vs Watch App
- Django FCM
- PencilKit
- ipad multitasking
- Flutter getter setter
- github actions
- Dart Factory
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함