OpenTTD GameScript API  20240328-master-gca53e134be
Public Types | Static Public Member Functions
GSError Class Reference

Class that handles all error related functions. More...

Inheritance diagram for GSError:

Public Types

enum  ErrorCategories {
  ERR_CAT_NONE,
  ERR_CAT_GENERAL,
  ERR_CAT_VEHICLE,
  ERR_CAT_STATION,
  ERR_CAT_BRIDGE,
  ERR_CAT_TUNNEL,
  ERR_CAT_TILE,
  ERR_CAT_SIGN,
  ERR_CAT_RAIL,
  ERR_CAT_ROAD,
  ERR_CAT_ORDER,
  ERR_CAT_MARINE,
  ERR_CAT_WAYPOINT,
  ERR_CAT_BIT_SIZE
}
 All categories errors can be divided in. More...
 
enum  ErrorMessages {
  ERR_NONE,
  ERR_UNKNOWN,
  ERR_PRECONDITION_FAILED,
  ERR_PRECONDITION_STRING_TOO_LONG,
  ERR_PRECONDITION_INVALID_COMPANY,
  ERR_NEWGRF_SUPPLIED_ERROR,
  ERR_GENERAL_BASE,
  ERR_NOT_ENOUGH_CASH,
  ERR_LOCAL_AUTHORITY_REFUSES,
  ERR_ALREADY_BUILT,
  ERR_AREA_NOT_CLEAR,
  ERR_OWNED_BY_ANOTHER_COMPANY,
  ERR_NAME_IS_NOT_UNIQUE,
  ERR_FLAT_LAND_REQUIRED,
  ERR_LAND_SLOPED_WRONG,
  ERR_VEHICLE_IN_THE_WAY,
  ERR_SITE_UNSUITABLE,
  ERR_TOO_CLOSE_TO_EDGE,
  ERR_STATION_TOO_SPREAD_OUT
}
 All general related error messages. More...
 

Static Public Member Functions

static ErrorCategories GetErrorCategory ()
 Check the membership of the last thrown error. More...
 
static GSErrorType GetLastError ()
 Get the last error. More...
 
static std::optional< std::string > GetLastErrorString ()
 Get the last error in string format (for human readability). More...
 

Detailed Description

Class that handles all error related functions.

Member Enumeration Documentation

◆ ErrorCategories

All categories errors can be divided in.

Enumerator
ERR_CAT_NONE 

Error messages not related to any category.

ERR_CAT_GENERAL 

Error messages related to general things.

ERR_CAT_VEHICLE 

Error messages related to building / maintaining vehicles.

ERR_CAT_STATION 

Error messages related to building / maintaining stations.

ERR_CAT_BRIDGE 

Error messages related to building / removing bridges.

ERR_CAT_TUNNEL 

Error messages related to building / removing tunnels.

ERR_CAT_TILE 

Error messages related to raising / lowering and demolishing tiles.

ERR_CAT_SIGN 

Error messages related to building / removing signs.

ERR_CAT_RAIL 

Error messages related to building / maintaining rails.

ERR_CAT_ROAD 

Error messages related to building / maintaining roads.

ERR_CAT_ORDER 

Error messages related to managing orders.

ERR_CAT_MARINE 

Error messages related to building / removing ships, docks and channels.

ERR_CAT_WAYPOINT 

Error messages related to building / maintaining waypoints.

ERR_CAT_BIT_SIZE 

DO NOT USE! The error bitsize determines how many errors can be stored in a category and what the offsets are of all categories.

◆ ErrorMessages

All general related error messages.

Enumerator
ERR_NONE 

Initial error value.

ERR_UNKNOWN 

If an error occurred and the error wasn't mapped.

ERR_PRECONDITION_FAILED 

If a precondition is not met.

ERR_PRECONDITION_STRING_TOO_LONG 

A string supplied was too long.

ERR_PRECONDITION_INVALID_COMPANY 

The company you use is invalid.

ERR_NEWGRF_SUPPLIED_ERROR 

An error returned by a NewGRF.

No possibility to get the exact error in an script readable format

ERR_GENERAL_BASE 

Base for general errors.

ERR_NOT_ENOUGH_CASH 

Not enough cash to perform the previous action.

ERR_LOCAL_AUTHORITY_REFUSES 

Local authority won't allow the previous action.

ERR_ALREADY_BUILT 

The piece of infrastructure you tried to build is already in place.

ERR_AREA_NOT_CLEAR 

Area isn't clear, try to demolish the building on it.

ERR_OWNED_BY_ANOTHER_COMPANY 

Area / property is owned by another company.

ERR_NAME_IS_NOT_UNIQUE 

The name given is not unique for the object type.

ERR_FLAT_LAND_REQUIRED 

The building you want to build requires flat land.

ERR_LAND_SLOPED_WRONG 

Land is sloped in the wrong direction for this build action.

ERR_VEHICLE_IN_THE_WAY 

A vehicle is in the way.

ERR_SITE_UNSUITABLE 

Site is unsuitable.

ERR_TOO_CLOSE_TO_EDGE 

Too close to the edge of the map.

ERR_STATION_TOO_SPREAD_OUT 

Station is too spread out.

Member Function Documentation

◆ GetErrorCategory()

static ErrorCategories GSError::GetErrorCategory ( )
static

Check the membership of the last thrown error.

Returns
The category the error belongs to.
Note
The last throw error can be acquired by calling GetLastError().

◆ GetLastError()

static GSErrorType GSError::GetLastError ( )
static

Get the last error.

Returns
An ErrorMessages enum value.

◆ GetLastErrorString()

static std::optional<std::string> GSError::GetLastErrorString ( )
static

Get the last error in string format (for human readability).

Returns
An ErrorMessage enum item, as string.