def get_value(obj, key, reference, default=None):
	"""
	Return the actual value described by obj[key].
	If obj[key] is not an integer, return it directly.
	Otherwise, consider obj[key] as an index within the reference list.
	If obj[key] is unreachable, return default.
	If default is None, raise the encoutered exception (either IndexError or KeyError).
	"""
	try:
		val = obj[key]
		return reference[val] if isinstance(val, int) else val
	except KeyError:
		if default is None:
			raise
		return default
	except IndexError:
		if default is None:
			raise
		return default