ExceptionHandling

Exception Handler

class CommonExceptionHandler

Bases: object

A class for catching and logging exceptions to a file on the system.

static catch_exceptions(mod_identifier, fallback_return=None)

Automatically catch exceptions thrown by the decorated function, log them to a file, and notify the player about the exception.

Note

Decorate functions with this decorator to catch and log exceptions

Parameters:
  • mod_identifier (Union[str, CommonModIdentity]) – The name or identity of the mod catching exceptions.

  • fallback_return (Any, optional) – A value to return upon an exception being caught. Default is None.

Returns:

A function wrapped to catch and log exceptions.

Return type:

Callable[…, Any]

static log_exception(mod_identifier, exception_message, exception=None, custom_file_path=None)

Manually log an exception with a custom message.

Parameters:
  • mod_identifier (Union[str, CommonModIdentity]) – The name or identity of the mod logging the exception.

  • exception_message (str) – A message to provide more information about the exception.

  • exception (Exception, optional) – The exception being logged. Default is None.

  • custom_file_path (str, optional) – A custom file path relative to The Sims 4 folder. Example: Value is ‘fake_path/to/directory’, the final path would be ‘The Sims 4/fake_path/to_directory’. Default is None.

Returns:

True, if the message was successfully logged. False, if the message was not successfully logged.

Return type:

bool

Stacktrace Util

class CommonStacktraceUtil

Bases: object

Utilities for accessing the full stack trace of your application.

static current_stack(skip=0)

Retrieve the current stack

Parameters:

skip (int) – The number of lines to skip

Return type:

Any

Returns:

A collection of the current stack.

static full_exception_info()

Like sys.exc_info, but includes the full traceback.

Return type:

Union[type, Any, FullTraceback]

static get_full_stack_trace()

Retrieve the full stacktrace from the current stack.

Return type:

List[str]

Returns:

A collection of stack trace strings.