I want to do some exception handling. I plan on using the __LINE__
and __FILE__
macros.
I have some header Vectors.hpp in which I implement some class for a vector structure. In this class I implement the operator []
and I want to throw an exception each time this operator is used with an out of bounds index. I test this class in some source test.cpp. I want then to be able to see the exact line in test.cpp where this happened.
However I know that the __LINE__
macro is disabled every time you include some header, so what I got is the line in Vectors.hpp where I handle the exception and not the line in test.cpp. Is there a nice way to get around this? Or, how would one implement his own __LINE__
macro?