Bird
0
0

Why must Swift functions that rethrow errors be marked with the throws keyword?

hard📝 Conceptual Q10 of 15
iOS Swift - Swift Language Essentials
Why must Swift functions that rethrow errors be marked with the throws keyword?
ATo catch errors automatically inside the function
BBecause all functions must have throws by default
CTo inform callers that the function can propagate errors
DTo prevent the function from throwing errors
Step-by-Step Solution
Solution:
  1. Step 1: Understand error propagation

    Functions that rethrow errors must declare throws to signal they can propagate errors to callers.
  2. Step 2: Clarify purpose of throws keyword

    throws is not automatic; it explicitly marks functions that can throw or rethrow errors.
  3. Final Answer:

    To inform callers that the function can propagate errors -> Option C
  4. Quick Check:

    throws marks error propagation = C [OK]
Quick Trick: Mark rethrowing functions with 'throws' to signal errors [OK]
Common Mistakes:
  • Thinking all functions throw by default
  • Confusing throws with catch
  • Assuming throws prevents errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes