The previous post on the special $exception local variable was really just some background to ask for a new special local called $return that holds what is being returned by the current method (basically, the return value that’s on, or going to be, on the stack, but without having to use windbg or the like). Certainly it would be nice if it also worked for arbitrary lambdas as well, but I’ll keep the scope of the request small for now
So, here’s the hypothetical source:
In this scenario, someone that’s debugging GetMyPath might want to see what’s being returned from the method. Currently, they’re stuck assigning it to a local (or similar) inside the method (or putting the burden on all the callers to similarly assign it) in order to then see it, something like:
What some people may not realize is that you can set a breakpoint at the end of a method and it gets hit no matter the (normal) exit path. For instance, for both of the callers in the above sample, they’ll hit such a breakpoint even though they exit via 2 different ‘return’ keywords.
Certainly there’s a school of thought (especially among old C++ developers) that you should create your return value at the top of your method and then return it at the bottom of your method (no multiple-return, no exception throwing, etc – inspired mostly by the various memory/resource handling patterns like needing to free allocated memory) but since the debugger obviously knows what the method is returning anyway, it would be awfully nice if it could show it to us