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

Throwing an custom error that doesn't normally happen.

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 different level errors look like.

timer.Simple( 0, function() -- A timer so that both errors are displayed. This is for demonstration purposes only. error( "I'M VERY IMPORTANT!!!" ) -- Normal error (level 1) end ) error( "It isn't important", 0 ) -- Notice the missing file path
Output:
[my_addon] It isn't important 1. error - [C]:-1 2. unknown - addons/my_addon/lua/autorun/my_code.lua:1 [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