Bird
0
0

What will happen if a child task in a Swift task group throws an error and it is not caught inside the group?

medium📝 Predict Output Q5 of 15
iOS Swift - Concurrency
What will happen if a child task in a Swift task group throws an error and it is not caught inside the group?
AThe program crashes immediately.
BThe error is ignored and other tasks continue normally.
COnly the failing task is cancelled, others continue.
DThe entire task group throws the error and cancels remaining tasks.
Step-by-Step Solution
Solution:
  1. Step 1: Understand error propagation in task groups

    If a child task throws and error is not caught, the task group propagates the error and cancels remaining tasks.
  2. Step 2: Identify behavior on uncaught errors

    This prevents partial results and ensures error handling at the group level.
  3. Final Answer:

    The entire task group throws the error and cancels remaining tasks. -> Option D
  4. Quick Check:

    Uncaught child error cancels group = true [OK]
Quick Trick: Uncaught errors in task groups cancel all tasks [OK]
Common Mistakes:
  • Assuming error is ignored
  • Thinking only failing task cancels
  • Believing program crashes immediately

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes