control-flow-throw-in-catch.ts 652 B

1234567891011121314
  1. // A `throw` inside a catch block does not land back in the same try: `catch` is a sibling of
  2. // `attempt`, so the jump resolves to the OUTER attempt — here there is none, so it aborts.
  3. // The step inside the try body may-throws into the catch; the step inside the catch has no
  4. // implicit exception edge (only try bodies get one).
  5. const plan = await agent("planner").ask<string>("plan");
  6. let result = "";
  7. try {
  8. result = await agent("worker").ask<string>(`do: ${plan}`);
  9. } catch {
  10. const salvage = await agent("salvage").ask<string>(`salvage: ${plan}`);
  11. if (salvage === "") throw new Error("unrecoverable");
  12. result = salvage;
  13. }
  14. return result;