There are lots of question/answers about exception handling in Mathematica. I still find exception handling in Mathematica too complicated to work with.
I find Maple much simpler and easier to understand when it comes to exception handling.
What would be the simplest translation of the following code from Maple to Mathematica?
foo:=proc(x,y) try x/y; catch: error "I give up, bad input"; end try; end proc;
The above defines a function
foo. The main exception handling is done using
try .... catch: ... end try
The call to
error terminates the function sends an error message to the caller (if any).
The use of
catch means to catch ANY error. (otherwise one can catch specific error.
So when calling the above in Maple this is the result
And when calling it as
foo(1,1) no error is generated.
I do not want to set separate functions and define external message string and tags and so on in Mathematica to do the above as shown in Error checking and trapping techniques with Throw and Catch for example which is very good but I find hard to follow and more complicated than in Maple. I'd like everything done inside the
try .. catch... end try is much simpler to use and understand.
What is the simplest way to implement similar code as the above Maple function?