my code crashed on map.at()
, which means it find a inexisted key.
i catch error in my main, but it seems only can catch the info of
EXCEPTION: _Map_base::at
and no location info, which means i need to check all at
function.
Is there any methods can catch this kind of error and print where it crash?
here is my code:
#include <iostream>
using namespace std;
void func() {
std::unordered_map<int, int> a;
cout << a.at(2) << endl;
}
void main() {
try {
func();
} catch (const std::exception& ex) {
printf("catch EXCEPTION: %s\n", ex.what()); // the mat at error catch here, How can i print the concrete location - func, in the message??????
}
}