#how to find out from which line I get into "errdefer"?

1 messages · Page 1 of 1 (latest)

signal leaf
#

I'm running many functions of the same type that have the same errorset and because of this I can't figure out exactly where I'm getting the error...
Or is it more correct to refuse errdefer in such cases?

manic flame
#

errdefer is mainly designed for cases where you need to free up resources in case of an error.
If you want different behavior for each error site then I think you should use catch blocks instead of errdefer:

    errorFunction1() catch |err| {
        ... // Your code that handles errors from function 1
        return err;
    };
    errorFunction2() catch |err| {
        ... // Your code that handles errors from function 2
        return err;
    };
quaint forge
#

alternatively split the function into 2

pub fn func() void {
  _func() catch |err| {
    // virtually same as errdefer
  }
}
fn _func() !void {
  return error.Fail;
}```
#

oh sorry that completely doesn't answer your question

wraith lintel
#

You can use @errorReturnTrace but I'm not entirely sure how that behaves inside errdefer

#

I think it should do exactly what you want actually, looking at the docs