func example() : async () {
try {
// If the intercanister call traps, the try will catch.
let result = await intercanisterCall();
// Now that subsequent message execution has been enqueued (iiuc),
// does this mean that the following will also be caught?
let triggerTrap = Principal.fromText("🤯🤦🦟");
} catch e {
Debug.print("Caught exception " #debug_show(e));
}
In this code, with Motoko 0.8 onwards, the catch clause should at least let you distinguish between
a failure to call intercanisterCall() (due to queue full) and the result of the call being an error by inspecting the error code of e, which should be (#call_error n) for some n in the former case and some other tag in the latter.
But you still cannot catch the trap from the call to Principal.fromText(), even after the await, though I’m wondering if we might be able to exploit an IC feature to support that (the IC call cleanup mechanism).