0PricingLogin
Zig Academy · Lesson

Comptime Validation and @compileError

Fail the build with clear messages.

Catch Mistakes Before Run Time

Zig lets you reject bad usage while the code compiles. The built-in @compileError stops the build with a message you write. 🛑

Fail with a Clear Message

@compileError takes a comptime string and aborts compilation, printing exactly that text so the caller knows what went wrong.

@compileError("this type is not supported");

All lessons in this course

  1. Reflecting Fields with @typeInfo
  2. Building Types with @Type
  3. Comptime Validation and @compileError
  4. Generating Code with comptime
← Back to Zig Academy