import traceback


def get_err_str(exception, message, trace=True):
    """Return an error string containing a message and exception details.

    Args:
        exception (obj): the exception object caught.
        message (str): the base error message.
        trace (bool): whether the traceback is included (default=True).

    """
    if trace:
        trace_str = "".join(traceback.format_tb(exception.__traceback__)).strip()
        err_str = "{}\nTYPE: {}\nDETAILS: {}\nTRACEBACK:\n\n{}\n" \
                  "".format(message, type(exception), exception, trace_str)
    else:
        err_str = "{}\nTYPE: {}\nDETAILS: {}\n".format(message, type(exception), exception)

    return err_str