Could we provide a API to catch `instruction limit error`

There’s no way catch hitting the instruction limit, but there are a few other options:

  1. Deterministic time slicing (DTS) basically automatically does what you want - it’ll pause your canister when it hits the limit and resume at the same point next time your canister is scheduled.

  2. You can break a large function up into smaller pieces a chain them together by having your canister call itself between each chunk. Then each chunk needs to finish within the instruction limit, but the total work can be much larger.

  3. If you need to dynamically trigger the self-call, you can use the performance counter to check when you might be getting close to the instruction limit.

3 Likes