This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: How to get more info about 'bad_function_call' ?
- From: Federico Terraneo <fede dot tft at hotmail dot it>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 27 Jan 2015 16:35:15 +0100
- Subject: Re: How to get more info about 'bad_function_call' ?
- Authentication-results: sourceware.org; auth=none
- References: <54C7A9F8 dot 70504 at tlinx dot org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
On 27/01/2015 16:08, Linda A. Walsh wrote:
> I have prog that terminates: terminate called after throwing an
> instance of 'std::bad_function_call' what(): bad_function_call
> Aborted (core dumped).
>
> on about the 8th call using it. If it was a simple indirect
> function pointer, I could, *possibly*, check to see if it was Null
> before the call or had an address outside of my program area, but
> it's not, and trying to coerce it into something to check hasn't
> been straightforward.
To me it looks like what you want is function::operator bool. If you
have an std::function named f, you can check if it's safe to call with
a simple
if(f) f(); else { /*unsafe to call*/ }
http://www.cplusplus.com/reference/functional/function/operator_bool/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iF4EAREIAAYFAlTHsDMACgkQbTKLH9en/LuUXQD9G4121+W1AakQcTb6jLxjuT+C
1mGDMRreuWbqLGoKzsoA+wYk5tv4pfqVl3wu7lya7CdE2YD4MVttO1k7fKYgshyL
=D7n0
-----END PGP SIGNATURE-----