On 2021-09-03 3:47 p.m., Alexander G. M. Smith wrote:
> If you want to turn exceptions inside-out, make the error object a
stack. Each level that wishes to can add a string explaining why it
failed. So you can drill down to see what happened.
On further thought, using a second area of memory to store the stack
isn't that complex. It's always being written to, not edited, so you
can sequentially write the strings, error codes and debug info into
memory. Don't even bother indexing it, just linearly search through it
to find a particular entry. There shouldn't be too many, well, except
in a recursive crash (change it into a queue when it gets too big and
forget the deeper entries?).
If it needs to be multitasking safe, use fixed size memory blocks and a
free list and a semaphore. Link in another block when you need more
space to append the data. Linearly searching through the error stack
now requires a jump once in a while, but overall speed is still O(n*n)
to find a particular stack entry. Not great, but good enough.
- Alex