Okay, a co-worker (Alexander Brissette) came up with a good solution using try-catch. It works like this:
<code that might produce error>
line = err.stack(1).line
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!