def catch_error(exception, log=None):
    """Catch error

    This method catches errors and prints them to the terminal. It also saves
    the errors to a log if provided.

    Parameters
    ----------
    exception : str
        Exception message string
    log : instance, optional
        Logging structure instance

    """

    if import_fail:
        err_txt = 'ERROR'
    else:
        err_txt = colored('ERROR', 'red')

    # Print exception to stdout.
    stream_txt = err_txt + ': ' + str(exception) + '\n'
    sys.stderr.write(stream_txt)

    # Check if a logging structure is provided.
    if not isinstance(log, type(None)):
        log_txt = 'ERROR: ' + str(exception) + '\n'
        log.exception(log_txt)