Handles proper system exit in case of critical exception.

    :param object: Object to decorate.
    :type object: object
    :return: Object.
    :rtype: object

def system_exit(object):
    """
    Handles proper system exit in case of critical exception.

    :param object: Object to decorate.
    :type object: object
    :return: Object.
    :rtype: object
    """

    @functools.wraps(object)
    def system_exit_wrapper(*args, **kwargs):
        """
        Handles proper system exit in case of critical exception.

        :param \*args: Arguments.
        :type \*args: \*
        :param \*\*kwargs: Keywords arguments.
        :type \*\*kwargs: \*\*
        """

        try:
            if object(*args, **kwargs):
                foundations.core.exit(0)
        except Exception as error:
            sys.stderr.write("\n".join(foundations.exceptions.format_exception(*sys.exc_info())))
            foundations.core.exit(1)

    return system_exit_wrapper