#prolly not good code help pls

1 messages · Page 1 of 1 (latest)

tribal bramble
#

i currently have a fn which has multiple instances of a catch followed by a block like this:

{
    try skipRemaining();
    return null;
}

is there any way to reduce the repitition?

sacred bolt
#

We'd need to see the rest of the code. A quick description of the context of what you're doing is usually helpful.

rocky monolith
#

just bubble up the error, create another function that swallows the error and returns null

summer crane
#

yeah probably best to use try instead of catch and have parent function handle the error.

If skipRemaining was made non-falliable, then you could keep in this function's context by having errdefer skipRemaining() at beginning

tribal bramble
#

it's actually a mix of orelse and catch, i ended up putting everything relevant in a block that is ?void

#

and if the block is null it does the cleanup

pulsar ridge
#

{
try skipRemaining();
return null;
}
returning an error or null seems odd

#

as try is catch |err| return err

rocky monolith
#

!?void is fine