Validate inputs before operations to prevent errors. Check types, ranges, and required fields early.
function processUser(user) {
if (!user) throw new Error("User required");
if (!user.email) throw new Error("Email required");
// Safe to proceed
}
Fail fast with clear messages rather than failing later with cryptic ones.