exceptions - MSUTeam/MSU GitHub Wiki

File path: scripts/config/msu/exceptions.nut

MSU defines some exceptions to be thrown when appropriate, these are used widely within the MSU codebase to make it easier to debug issues in implementations.

These are all functions in the table ::MSU.Exception and accept a single argument which is then converted to a string via .tostring() and printed in the exception's text.

KeyNotFound

::MSU.Exception.KeyNotFound( _key )

Thrown when attempting to access a value of a table/instance when the key doesn't exist.

NotConnected

::MSU.Exception.NotConnected( _screen = "" )

Thrown by a ui_screen if attempting to interact with a JSHandle that hasn't been initialized yet. Vanilla fails silently in these situations which can be undesirable when trying to debug a mod.

AlreadyInState

::MSU.Exception.AlreadyInState( _screen = "" )

Thrown by a ui_screen if attempting to show a screen that is already shown or hide a screen that is already hidden. Vanilla fails silently in these situations which can be undesirable when trying to debug a mod.

InvalidValue

::MSU.Exception.InvalidValue( _string = "" )

Thrown when the type of a passed argument is correct but its value is unacceptable.

InvalidType

::MSU.Exception.InvalidType( _string = "" )

Thrown when the type of a passed argument doesn't match the type expected by the function.

DuplicateKey

::MSU.Exception.DuplicateKey( _key )

Thrown when trying to set a key that already exists in a table, and the table is designed to rely on a single assignment to that key.

Example

::MSU.asWeakTableRef <- function( _object )
{
   if (typeof _object == "instance")
   {
       if (_object instanceof ::WeakTableRef) return _object;
       throw ::MSU.Exception.InvalidType(_object);
   }
   return ::WeakTableRef(_object);
}

// The above code will throw the InvalidType exception if _object is an
// instance of a class other than ::WeakTableRef.
⚠️ **GitHub.com Fallback** ⚠️