.parse() Throws (and Crashes Your App)
.parse() throws a ZodError the moment validation fails. If nothing catches it, that exception bubbles straight up and takes down your request handler, your script, or your whole app. This demo runs the same schema through .safeParse() instead, so a bad input shows up as a result instead of a crash. Try fixing the input below to see the success path.
import { z } from 'zod';
const schema = z.object({ name: z.string(), age: z.number() });
// Throws a ZodError. If nothing catches it, your app crashes.
const data = schema.parse(input);type Schema = {
name: string;
age: number;
}
// If age is the wrong type, schema.parse(input)
// throws immediately. No try/catch, no survivors.- age