Skip to content

Taxonomy

Catch that returns success

The error path returns a value the caller cannot tell from a real one.

What it looks like

  • catch { return []; } or return null where the caller treats those as legitimate answers.
  • catch { return false; } in a function whose false means 'not allowed'.
  • A default value produced on failure that also occurs naturally.

Why it survives review

Returning a default from a catch is a real pattern and often the right one. It becomes a defect only when the default is *ambiguous* — when the caller cannot distinguish 'there were no results' from 'the query failed'. That distinction lives in the caller, so it is invisible while reading this function alone.

How to see it

  1. Ask whether the fallback value is one the function could return on a successful path. If it is, the caller cannot tell them apart.
  2. For a permission or validation check, a failure that returns false is safe; one that returns true is a hole. Check which way round it is.
  3. Follow the return value to its first caller before deciding the catch is fine.

A minimal pair

Correct

catch (error) {
throw new LookupFailed(error);
}

Defective

catch (error) {
return [];
}

A failing backend now looks exactly like an empty result set, and the page renders 'no items found'.

Practise it

No exercise in the corpus sets this class yet. The lesson stands on its own — the corpus grows by adding subjects, and pretending otherwise would hide the gap.