2

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.

enter image description here

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?

user305883
  • 457
  • 2
  • 10

0 Answers0