I am making a command line program. For exception handling, in the throw part, I want the code to display the location where the exception had occurred. For example an exception occurred in, Display.hpp> class display> int Print_Text(); So the throw part of the code should display the location of the exception as explained above. Now, what exactly I want to know is the code that automatically detects what file, class and function the code is located in, and then I can display that to know where an exception occurred.
CodePudding user response:
If you can use C 20 I'd suggest std::source_location.
CodePudding user response:
While possible with __FILE__
and __LINE__
, I suggest you don't do that. Such information is not helpful for your users, it's only useful for developers.
Instead, use developer's means like crash dumps (core dumps) and PDB files (symbols) to get the method names, line numbers etc.