Skip to main content
InterviewHubPRO
Section Overview
Q46

Question 46 of 50

Part 3: Runtime Internals, Swift 6 Safety & Systems Programming (25 - 35)

92%
Swift & Concurrency (50 Qs)•Part 3: Runtime Internals, Swift 6 Safety & Systems Programming (25 - 35)

Error Handling: `Result`, typed throws in Swift 6 (`throws(MyError)`), and `rethrows`.

senior LevelCode ExampleswiftRuntime Internals

In Simple Words:

  • Untyped Throws (Classic Swift): func fetch() throws erases error types to any Error.
  • Typed Throws (Swift 6):
    swift
    enum NetworkError: Error { case timeout, unauthorized }
    func request() throws(NetworkError) -> Data { ... }
    
    Callers receive a strongly typed NetworkError in catch blocks without type casting!
  • rethrows: A function throws an error only if one of its closure arguments throws an error (e.g. map, filter).