Garry's Mod Wiki

error

You might be looking for the "Error" function, which has the same name as this function.
  error( string message, number errorLevel = 1 )

Description

Throws a Lua error and breaks out of the current call stack.

Arguments

1 string message
The error message to throw.
2 number errorLevel = 1
The level to throw the error at.

Example

Calling an custom error that doesn't actually exist.

error("Because I wanted!")
Output:
[my_addon] addons/my_addon/lua/autorun/my_code.lua:1: Because I wanted! 1. error - [C]:-1 2. unknown - addons/my_addon/lua/autorun/my_code.lua:1

Example

Shows what a low level (0) error looks like.

error("It isn't important",0)
Output:
[my_addon] It isn't important 1. error - [C]:-1 2. unknown - addons/my_addon/lua/autorun/my_code.lua:1

Example

Shows what a high level (1) error looks like.

error("I'M VERY IMPORTANT!!!",1)
Output:
[my_addon] addons/my_addon/lua/autorun/my_code.lua:1: I'M VERY IMPORTANT!!! 1. error - [C]:-1 2. unknown - addons/my_addon/lua/autorun/my_code.lua:1