Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
a899cecb
Commit
a899cecb
authored
Jul 13, 2020
by
Vladimir Goncharov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup a bulky expression, document implementation details
parent
4ebbfea6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
8 deletions
+30
-8
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+30
-8
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
a899cecb
...
@@ -4741,6 +4741,35 @@ class ExceptionMatcherImpl {
...
@@ -4741,6 +4741,35 @@ class ExceptionMatcherImpl {
}
}
};
};
// If the matchee raises an exception of a wrong type, we'd like to
// catch it and print its message and type. To do that, we add an additional
// catch clause:
//
// try { ... }
// catch (const Err&) { /* an expected exception */ }
// catch (const std::exception&) { /* exception of a wrong type */ }
//
// However, if the `Err` itself is `std::exception`, we'd end up with two
// identical `catch` clauses:
//
// try { ... }
// catch (const std::exception&) { /* an expected exception */ }
// catch (const std::exception&) { /* exception of a wrong type */ }
//
// This can cause a warning or an error in some compilers. To resolve
// the issue, we use a fake error type whenever `Err` is `std::exception`:
//
// try { ... }
// catch (const std::exception&) { /* an expected exception */ }
// catch (const NeverThrown&) { /* exception of a wrong type */ }
using
DefaultExceptionType
=
typename
std
::
conditional
<
std
::
is_same
<
typename
std
::
remove_cv
<
typename
std
::
remove_reference
<
Err
>::
type
>::
type
,
std
::
exception
>::
value
,
const
NeverThrown
&
,
const
std
::
exception
&>::
type
;
public
:
public
:
ExceptionMatcherImpl
(
Matcher
<
const
Err
&>
matcher
)
ExceptionMatcherImpl
(
Matcher
<
const
Err
&>
matcher
)
:
matcher_
(
std
::
move
(
matcher
))
{}
:
matcher_
(
std
::
move
(
matcher
))
{}
...
@@ -4771,14 +4800,7 @@ class ExceptionMatcherImpl {
...
@@ -4771,14 +4800,7 @@ class ExceptionMatcherImpl {
}
else
{
}
else
{
return
true
;
return
true
;
}
}
}
catch
(
}
catch
(
DefaultExceptionType
err
)
{
typename
std
::
conditional
<
std
::
is_same
<
typename
std
::
remove_cv
<
typename
std
::
remove_reference
<
Err
>::
type
>::
type
,
std
::
exception
>::
value
,
const
NeverThrown
&
,
const
std
::
exception
&>::
type
const
&
err
)
{
#if GTEST_HAS_RTTI
#if GTEST_HAS_RTTI
*
listener
<<
"throws an exception of type "
*
listener
<<
"throws an exception of type "
<<
GetTypeName
(
typeid
(
err
))
<<
" "
;
<<
GetTypeName
(
typeid
(
err
))
<<
" "
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment