def METHOD_NAME(cls, hash):
    # Hash contains class, message, backtrace, and instance_variables
    error_class = None
    try:
        error_class = globals()[hash["class"]]
    except KeyError:
        error_class = RuntimeError
        if "message" not in hash and "class" in hash:
            hash["message"] = hash["class"]
    error = None
    if error_class == RuntimeError and "message" in hash:
        error = error_class(hash["message"])
    else:
        error = error_class()
    if "instance_variables" in hash:
        for name, value in hash["instance_variables"].items():
            # Backend is Ruby so remove '@' from instance_variables
            setattr(error, name[1:], value)
    return error