CommandHelper icon indicating copy to clipboard operation
CommandHelper copied to clipboard

Provide `nocatch` keyword

Open LadyCailin opened this issue 3 years ago • 4 comments

A nocatch block is a block which may throw an exception, which is ignored (except if scream-errors is on.)

nocatch {
    _codeThatThrowsAnException();
}

is compiled to

try {
    _codeThatThrowsAnException();
} catch(Exception @ex) {
    // Ignored
}

LadyCailin avatar Nov 28 '22 11:11 LadyCailin

This is a valid use-case, but why create a new keyword for this? I would propose a different syntax instead:

try {
    _codeThatThrowsAnException();
}

Pieter12345 avatar Nov 28 '22 20:11 Pieter12345

I'd rather it be explicit. This could be an accidental omission, whereas a separate nocatch block is very explicit.

LadyCailin avatar Nov 28 '22 20:11 LadyCailin

I am with Pieter on this one. If someone accidentally leaves off catch that's their own fault. Personally it makes a lot of sense to me to just make the catch part optional.

lukecfairchild avatar Jan 14 '23 06:01 lukecfairchild

If we added this new block keyword (and it wasn't try), I think something along the lines of catchall, ignore, or suppress make more sense to me than nocatch.

However, most cases where I use try(function()) I do not require support for multiple statements, and places where I would need multiple statements it makes sense to just use the normal catch(Exception @ignore){}. So a single line keyword format would be nicer for me.

PseudoKnight avatar Jan 27 '23 14:01 PseudoKnight