3 ms·
A less flexible and less elegant way to avoid stack unwind in other languages would be to have a parameter that tells the invoked function what to do if an erro
by fauigerzigerk 14y ago
A less flexible and less elegant way to avoid stack unwind in other languages would be to have a parameter that tells the invoked function what to do if an error occurs:
def parse_log_entry(text, err_fn):
entry = parse(text)
if entry is None:
entry = err_fn(text)
return entry
Instead of passing a function, err_fn could also be some kind of resolver that finds a function for a condition name, or there could be a global recovery function:
def parse_log_entry(text):
entry = parse(text)
if entry is None:
entry = recover('invalid_log_entry', text)
return entry