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

  • From: looncraz <looncraz@xxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 5 Sep 2021 09:09:53 -0500

I think if we're looking into building error stacks and the lack we should also look into modifying the compiler to silently add error handling.

For example, if I am returning an object by value from a method:

    MyObject        MyMethod();

Instead of needing to wrap MyObject with BError<MyObject> or BExpected<MyObject> the compiler could default to silently wrapping it... but hiding that entirely...

    auto value = MyMethod(); // value contains copy of type MyObject, but is silently wrapped with BError
    if (BError::HasError(value)) {
        // handle error
        BError::GetError(value).PrintToStream();
        BError::Throw(value, "MyFunc can't continue due to error"); // chained error with appended message
        return;
    }
    // use value directly...
    value.DoSomething();
    // address of value is address of object
    MyObject* ptrToValue = &value;

Then we can return whatever makes sense without wrapping everything or resorting to the headaches that exceptions can sometimes cause.

Just a thought.

--The loon

Other related posts: