Generic try, catch in boost::lexical_cast

Hi, Whilst updating SVN today I spotted a change to boost::lexical_cast, https://svn.boost.org/trac/boost/changeset/71958, which introduces a try { } catch(...) { } construction. I'm curious as to why this catch-all is needed since it seems to be there to deal with boost::numeric_cast exceptions and whether it could lead to a std::bad_alloc being rethrown as a bad_lexical_cast. Kind regards, Jeroen Habraken

2011/5/19 Jeroen Habraken <vexocide@gmail.com>:
Hi,
Whilst updating SVN today I spotted a change to boost::lexical_cast, https://svn.boost.org/trac/boost/changeset/71958, which introduces a try { } catch(...) { } construction. I'm curious as to why this catch-all is needed since it seems to be there to deal with boost::numeric_cast exceptions and whether it could lead to a std::bad_alloc being rethrown as a bad_lexical_cast.
numeric_cast does not use new operator, so std::bad_alloc will not be rethrown as a bad_lexical_cast. But you are right, and it will be more appropriate to catch only boost::numeric_cast exceptions. I`ll fix it in next commit. Great thanks for reporting this. Best regards, Antony Polukhin

On 19 May 2011 18:32, Antony Polukhin <antoshkka@gmail.com> wrote:
2011/5/19 Jeroen Habraken <vexocide@gmail.com>:
Hi,
Whilst updating SVN today I spotted a change to boost::lexical_cast, https://svn.boost.org/trac/boost/changeset/71958, which introduces a try { } catch(...) { } construction. I'm curious as to why this catch-all is needed since it seems to be there to deal with boost::numeric_cast exceptions and whether it could lead to a std::bad_alloc being rethrown as a bad_lexical_cast.
numeric_cast does not use new operator, so std::bad_alloc will not be rethrown as a bad_lexical_cast. But you are right, and it will be more appropriate to catch only boost::numeric_cast exceptions. I`ll fix it in next commit. Great thanks for reporting this.
Thanks!
Best regards, Antony Polukhin
Jeroen

Antony Polukhin wrote:
2011/5/19 Jeroen Habraken <vexocide@gmail.com>:
Hi,
Whilst updating SVN today I spotted a change to boost::lexical_cast, https://svn.boost.org/trac/boost/changeset/71958, which introduces a try { } catch(...) { } construction. I'm curious as to why this catch-all is needed since it seems to be there to deal with boost::numeric_cast exceptions and whether it could lead to a std::bad_alloc being rethrown as a bad_lexical_cast.
numeric_cast does not use new operator, so std::bad_alloc will not be rethrown as a bad_lexical_cast. But you are right, and it will be more appropriate to catch only boost::numeric_cast exceptions. I`ll fix it in next commit. Great thanks for reporting this.
Hi, I see new test have been added. Have you run the new tests with the previous lexical cast version? Best, Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/Generic-try-catch-in-boost-lexical-cast-t... Sent from the Boost - Dev mailing list archive at Nabble.com.

2011/5/20 Vicente Botet <vicente.botet@wanadoo.fr>:
Hi,
I see new test have been added. Have you run the new tests with the previous lexical cast version?
Yes, I have. They passed successfully. Vicente, you have commented some time ago a ticket https://svn.boost.org/trac/boost/ticket/4946 If you have some time and still can reproduce this bug, please check the fix. It is just about adding #include <boost/utility/value_init.hpp> and using boost::value_initialized<Target> result; . Best regards, Antony Polukhin

Antony Polukhin wrote:
2011/5/20 Vicente Botet <vicente.botet@wanadoo.fr>:
Hi,
I see new test have been added. Have you run the new tests with the previous lexical cast version?
Yes, I have. They passed successfully.
Vicente, you have commented some time ago a ticket https://svn.boost.org/trac/boost/ticket/4946 If you have some time and still can reproduce this bug, please check the fix. It is just about adding #include <boost/utility/value_init.hpp> and using boost::value_initialized<Target> result; .
Hi, I have never tried to reproduce the tis bug. It was just that the proposed patch introduced a new warning. Now that you have changed the patch there is no reason this specific warning appears. Best, Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/Generic-try-catch-in-boost-lexical-cast-t... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (3)
-
Antony Polukhin
-
Jeroen Habraken
-
Vicente Botet