|First, make sure you're creating a debug build. Whatever IDE you're using should have a Build or Compile config section, so take a look and make sure that's set. Your IDE should have a built in link to the debugger, so just run the program in the debugger. When the error is thrown, the debugger should stop the program and allow you to examine the state of the program. If you need to use the command line, here's an example to help you get started:
$ cat bad_alloc.cpp
size_t lim = 2;
int *arr = new int[lim];
lim *= 2;
$ g++ -m32 -ggdb bad_alloc.cpp -o bad_alloc
$ gdb bad_alloc
Reading symbols from bad_alloc...
Starting program: /home/ebacon/tmp/c++/bad_alloc
terminate called after throwing an instance of 'std::bad_array_new_length'
Program received signal SIGABRT, Aborted.
0xf7fce559 in __kernel_vsyscall ()
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.32-10.fc33.i686 libgcc-10.3.1-1.fc33.i686
(gdb) frame 8
8 int *arr = new int[lim];
(gdb) p lim
$1 = 536870912
A debugging session is active.
Inferior 1 [process 3076940] will be killed.
Quit anyway? (y or n) y
Hopefully, that's enough to get you started. If you need more, then Google is your friend.
Keep Calm and Carry On