Sure, unless you've written the program to handle that. However, what I wished to do was to show 'guesser' what's available out of the box and that even that's better than simply stopping with an "Error: the sky has fallen" message, unless, of course its pointing out that an essential file is either missing or unreadable, when simply stopping and saying so is about all you can do and will tell the user all he needs to know to fix the problem.
About the best semi-automatic, no-brainer approach to that is Java's stack dump. Anything better will need a bit of thought,
FWIW, one of the best solutions I've seen was in the guts of ICL's George
3 OS. That used a circular buffer that held about 100 messages. Tracing info was written to it during normal operation and it was dumped to the printer if a fatal error ocurred. In fact, George used two buffers, one quite fine grained and the other was much coarser: the fine-grained buffer content corresponded to the last 3 or so entries in the coarse buffer. The benefit of this approach is that you get the history leading to the error while a stack dump shows where you were but not really what led to the crash.I've used this approach with just a single buffer in long running programs. In them I dumped the buffer when a serious error ocurred, followed by said serious error message. Then, depending on the severity of the error, the program might go on running or terminate at that point.
And this is precisely what the circular buffer gives you: the immediate history leading to the error without the preceding megabytes of log file to wade through and chew up disk space.