Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ exception handling with source code line info

Tags:

c++

exception

Is there a way catch an exception like access violation and get information about on which line an exception occurred? This would be very good for debugging purposes, especially for testers..

My environment is Windows with VC++ on VS2008

like image 995
whoi Avatar asked Aug 05 '26 04:08

whoi


2 Answers

An access violation is not an exception in C++ terms, so the answer is in general "no". Concieveably, your specific implementation might have a feature that turns access violations into C++ exceptions - you need to specify what compiler & platform you are using.

In case you really want to log info about C++ exceptions (AV is not one) thrown from your code, you can use macros __FILE__ and __LINE__ within constructors of your exception types.

like image 28
Nemanja Trifunovic Avatar answered Aug 06 '26 20:08

Nemanja Trifunovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!