9.6 -error() and -warning() directives

The directive -error(Term) causes a compilation error.

Example:

  1. -module(t).
  2. -export([version/0]).
  3.  
  4. -ifdef(VERSION).
  5. version() -> ?VERSION.
  6. -else.
  7. -error("Macro VERSION must be defined.").
  8. version() -> "".
  9. -endif.

The error message will look like this:

  1. % erlc t.erl
  2. t.erl:7: -error("Macro VERSION must be defined.").

The directive -warning(Term) causes a compilation warning.

Example:

  1. -module(t).
  2. -export([version/0]).
  3.  
  4. -ifndef(VERSION).
  5. -warning("Macro VERSION not defined -- using default version.").
  6. -define(VERSION, "0").
  7. -endif.
  8. version() -> ?VERSION.

The warning message will look like this:

  1. % erlc t.erl
  2. t.erl:5: Warning: -warning("Macro VERSION not defined -- using default version.").

The -error() and -warning() directives were added in OTP 19.