[haiku-development] Re: Error Handling (was: Re: Plan for NetServices Kit (v2))

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 03 Sep 2021 20:23:31 +0000

3 septembre 2021 22:07 "Alexander G. M. Smith" <agmsmith@xxxxxx> a écrit:

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.

Nothing is impossible, but that is a lot of effort and complexity to
essentially do "exceptions without actually using exceptions".
-- 
Adrien.


Other related posts: