In python I can write fallback values like:
def f():
try:
// do smtg
return stgm
except:
// error was met: return fallback
return fallback
and can easily map that function.
In mathematica I have a dataset, I would like to append a column as a result of a function applied to a row, and throw a fallback or handle that error is function fails.
I would like to consider:
- throw a fallback value
- handle the error, by skipping the whole line in the Dataset (like I could do in python Pandas)
In mathematica, if there is an exception, map of the function will be aborted with a Failure. I don't know what to do with this message.
I looked at : Exception/Error handling using returns codes
I am looking at simpler pattern that could do:
f[row_] := row["col1"] / row["col2"] // handle try except ?
// ds is Dataset
ds[All, Append[#, "col3" -> f[#]] &]
How to do handle try / except exeptions in Mathematica?
Query
and probably look atFailureAction
too. If you still think you need exceptions proper then you should probably look atCatch
/Throw
, and you should also take a look at this too $\endgroup$ – user42582 Apr 25 '19 at 14:59