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)

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.
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: int = 0) → Any

Retrieve the current stack

Parameters:skip – The number of lines to skip
Returns:A collection of the current stack.
static full_exception_info() → Union[type, Any, sims4communitylib.exceptions.common_stacktrace_utils.FullTraceback]

Like sys.exc_info, but includes the full traceback.

static get_full_stack_trace() → List[str]

Retrieve the full stacktrace from the current stack.

Returns:A collection of stack trace strings.