CancellationScope use

I have a parent workflow A. Under A, an activity runs tasks D, C, and D asynchronously. Task B fails. The exception thrown by task B is captured by workflow A. However, task C and task D need to execute some methods after workflow A captures the exception thrown by task B. However, the following exception occurs during task execution.

io.grpc.StatusRuntimeException: NOT_FOUND: workflow execution already completed

How to write the code?