Disclaimer: I don't program with try-catch blocks and so don't know much about how they should be used.
Consider different ways of attempting to evaluate the hypergeometric function with invalid inputs. In all cases, the issue is that the second argument (-1) is greater than the second element of the first argument (-2). Case 1:
Call hypergeom directly
hypergeom([1,-2],sym(-1),-1)
string({ME.stack.name}.')
end
ME =
MException with properties:
identifier: 'symbolic:specfunc:InvalidArgument'
message: 'Invalid arguments.'
cause: {}
stack: [6×1 struct]
Correction: []
ans =
"symbolicEngine.evalin2sym"
"symbolicEngine.feval2sym_Infsingularity"
"hypergeom"
"LiveEditorEvaluationHelperEeditorId"
"fevalMatlab"
"fevalJSON"
The message tells us that that the input arguments are invalid (though it would be nice if the message actually said what caused the arguments to be invalid), and we see hypergeom somwhere in the call stack. Note that there are two flavors of hypergeom
which hypergeom -all
/MATLAB/toolbox/symbolic/symbolic/hypergeom.m
/MATLAB/toolbox/symbolic/symbolic/@sym/hypergeom.m % sym method
which hypergeom([1,-2],sym(-1),-1)
/MATLAB/toolbox/symbolic/symbolic/@sym/hypergeom.m % sym method
and that we've called the sym method (if that's important, I have no idea).
Case 2:
Define a symbolic expression and subs into that
subs(hypergeom([1,-2],t,-1),t,-1)
string({ME.stack.name}.')
end
ME =
MException with properties:
identifier: 'symbolic:kernel:DivisionByZero'
message: 'Division by zero.'
cause: {}
stack: [4×1 struct]
Correction: []
ans =
"subs"
"LiveEditorEvaluationHelperEeditorId"
"fevalMatlab"
"fevalJSON"
Now we get a divide by zero message, and there is no trace of hypergeom in the stack. How is one to figure out where the problem lies?
Case 3:
Define a symbolic function and evaluate at -1
f(t) = hypergeom([1,-2],t,-1);
string({ME.stack.name}.')
end
ME =
MException with properties:
identifier: 'symbolic:kernel:DivisionByZero'
message: 'Division by zero.'
cause: {}
stack: [4×1 struct]
Correction: []
ans =
"symfun.subsref"
"LiveEditorEvaluationHelperEeditorId"
"fevalMatlab"
"fevalJSON"
Same divide by zero, but no indication of hypergeom. subsref is now the culprit, presumably that's an overload to evaluate the symfun with paren indexing.
Case 4:
Define a different symbolic function and evaluate it for an input that should be the same as Case 3
fu(t) = hypergeom([1, -(2*t)/pi], -(2*t - pi)/pi, -1)
fu(t) =

string({ME.stack.name}.')
end
ME =
MException with properties:
identifier: 'symbolic:specfunc:InvalidArgument'
message: 'Invalid arguments.'
cause: {}
stack: [4×1 struct]
Correction: []
ans =
"symfun.subsref"
"LiveEditorEvaluationHelperEeditorId"
"fevalMatlab"
"fevalJSON"
Why isn't this result exaclty the same as Case 3?
I started down this path when I ran into the error w/o using try/catch
fu(sym(pi))
Error using indexing (line 213)
Invalid arguments.
I assume the error is shown for "indexing" because it comes from subsref? IDK. On the face of it, I had no idea where indexing would come into play and it took me a while to figure out the real problem was with the inputs to hypergeom.
From a user (at least this user) perspective, I'd expect the error message to be the same in all cases because all four cases are attempting to do the same thing: evaluate hypergeom for (invalid) prescribed inputs. Is that expectation unreasonable? Would it be feasible to make that happen using the multiple try/catch blocks that I assume are in play here?
And why isn't hypergeom shown in the call stack for Cases 2-4? Does that mean those cases never got to a call to hypergeom?