Skip to content

Replace try-catch with nullptr checks #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/util/std_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ namespace detail // NOLINT
template<typename Tag>
inline bool can_cast_code_impl(const exprt &expr, const Tag &tag)
{
try
if(const auto ptr = expr_try_dynamic_cast<codet>(expr))
{
return expr_dynamic_cast<codet>(expr).get_statement()==tag;
}
catch(const std::bad_cast &)
{
return false;
return ptr->get_statement() == tag;
}
return false;
}

} // namespace detail
Expand Down Expand Up @@ -1244,14 +1241,11 @@ namespace detail // NOLINT
template<typename Tag>
inline bool can_cast_side_effect_expr_impl(const exprt &expr, const Tag &tag)
{
try
{
return expr_dynamic_cast<side_effect_exprt>(expr).get_statement()==tag;
}
catch(const std::bad_cast &)
if(const auto ptr = expr_try_dynamic_cast<side_effect_exprt>(expr))
{
return false;
return ptr->get_statement() == tag;
}
return false;
}

} // namespace detail
Expand Down