問題文
A team needs callers to distinguish a validation failure from other failures with instanceof, and the log must show a distinctive name. What should the team define?
選択肢
- A string that starts with a fixed prefix naming the category, thrown directly to the caller.
- A plain object with a code property, thrown as it is, because throwing an object keeps the payload small and instanceof still works against the constructor that produced the object literal at the point where it was created.
- A class that extends Error, calls super with the message and sets its own name in the constructor.
- A function that returns an Error object without throwing it, because returning the error lets the caller decide whether to treat it as a failure and instanceof then works on the returned value.