Okay, a co-worker (Alexander Brissette) came up with a good solution using try-catch. It works like this:
try
<code that might produce error>
catch err
err
err.stack
line = err.stack(1).line
end
This prints the error, filename, and line number. You can also put a breakpoint in the "catch" block so you can see all your variables when an error occurs. You could put an entire function inside the try block. And it works even when the function is called from within Simulink!