Skip to content

Commit 22ea97a

Browse files
committed
chore: clean up catch sites
1 parent 4fb586d commit 22ea97a

File tree

8 files changed

+79
-50
lines changed

8 files changed

+79
-50
lines changed

include/mrdox/Support/Error.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,26 @@ class [[nodiscard]] MRDOX_DECL
169169
170170
@pre this->failed()
171171
*/
172-
[[noreturn]] void Throw() const;
172+
[[noreturn]] void Throw() const&;
173+
174+
/** Throw Exception(std::move(*this))
175+
176+
@pre this->failed()
177+
*/
178+
[[noreturn]] void Throw() &&;
173179

174180
/** Throw Exception(*this), or do nothing if no failure.
175181
*/
176-
void maybeThrow() const
182+
void maybeThrow() const&
183+
{
184+
if(! failed())
185+
return;
186+
Throw();
187+
}
188+
189+
/** Throw Exception(std::move(*this)), or do nothing if no failure.
190+
*/
191+
void maybeThrow() &&
177192
{
178193
if(! failed())
179194
return;

source/-adoc/AdocGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ createExecutors(
4242
{
4343
group.emplace(domCorpus, *options);
4444
}
45-
catch(Error const& e)
45+
catch(Exception const& ex)
4646
{
47-
return e;
47+
return ex.error();
4848
}
4949
}
5050
return group;

source/Support/Error.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,18 @@ Error(
8484
loc_ = loc;
8585
}
8686

87-
void
88-
Error::
89-
Throw() const
87+
void Error::Throw() const&
9088
{
9189
MRDOX_ASSERT(failed());
92-
// VFALCO should we use std::move?
9390
throw Exception(*this);
9491
}
9592

93+
void Error::Throw() &&
94+
{
95+
MRDOX_ASSERT(failed());
96+
throw Exception(std::move(*this));
97+
}
98+
9699
SourceLocation::
97100
SourceLocation(
98101
source_location const& loc) noexcept

source/Support/ExecutorGroup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ run(std::unique_lock<std::mutex> lock)
117117
work(scope.get());
118118
lock.lock();
119119
}
120-
catch(Error const& err)
120+
catch(Exception const& ex)
121121
{
122122
lock.lock();
123-
impl_->errors.emplace(err);
123+
impl_->errors.emplace(ex.error());
124124
}
125125
catch(std::exception const& ex)
126126
{
127127
// Any exception which is not
128-
// derived from Error should
128+
// derived from Exception should
129129
// be reported and terminate
130130
// the process immediately.
131131
reportUnhandledException(ex);

source/Support/Generator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ buildOneString(
100100
dest = ss.str();
101101
return {};
102102
}
103+
catch(Exception const& ex)
104+
{
105+
return ex.error();
106+
}
103107
catch(std::exception const& ex)
104108
{
105109
return formatError("buildOne threw \"{}\"", ex.what());

source/Support/ThreadPool.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ post(
7474
auto sp = std::make_shared<
7575
any_callable<void(void)>>(std::move(f));
7676
impl_->async(
77-
[sp]
77+
[sp]
78+
{
79+
try
80+
{
81+
(*sp)();
82+
}
83+
catch(std::exception const& ex)
7884
{
79-
try
80-
{
81-
(*sp)();
82-
}
83-
catch(std::exception const& ex)
84-
{
85-
// Any exception which is not
86-
// derived from Error should
87-
// be reported and terminate
88-
// the process immediately.
89-
reportUnhandledException(ex);
90-
}
91-
});
85+
// Any exception which is not
86+
// derived from Error should
87+
// be reported and terminate
88+
// the process immediately.
89+
reportUnhandledException(ex);
90+
}
91+
});
9292
}
9393

9494
//------------------------------------------------
@@ -155,26 +155,26 @@ post(
155155
auto sp = std::make_shared<
156156
any_callable<void(void)>>(std::move(f));
157157
impl_->taskGroup.async(
158-
[&, sp]
158+
[&, sp]
159+
{
160+
try
161+
{
162+
(*sp)();
163+
}
164+
catch(Exception const& ex)
165+
{
166+
std::lock_guard<std::mutex> lock(impl_->mutex);
167+
impl_->errors.emplace(ex.error());
168+
}
169+
catch(std::exception const& ex)
159170
{
160-
try
161-
{
162-
(*sp)();
163-
}
164-
catch(Error const& err)
165-
{
166-
std::lock_guard<std::mutex> lock(impl_->mutex);
167-
impl_->errors.emplace(std::move(err));
168-
}
169-
catch(std::exception const& ex)
170-
{
171-
// Any exception which is not
172-
// derived from Error should
173-
// be reported and terminate
174-
// the process immediately.
175-
reportUnhandledException(ex);
176-
}
177-
});
171+
// Any exception which is not
172+
// derived from Error should
173+
// be reported and terminate
174+
// the process immediately.
175+
reportUnhandledException(ex);
176+
}
177+
});
178178
}
179179

180180
} // mrdox

source/Tool/ConfigImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ createConfigFromYAML(
187187
workingDir, addonsDir, configYaml, extraYaml);
188188
return config;
189189
}
190-
catch(Error const& err)
190+
catch(Exception const& ex)
191191
{
192-
return err;
192+
return ex.error();
193193
}
194194
}
195195

@@ -222,9 +222,9 @@ loadConfigFile(
222222
workingDir, addonsDir, *text, extraYaml);
223223
return config;
224224
}
225-
catch(Error const& err)
225+
catch(Exception const& ex)
226226
{
227-
return err;
227+
return ex.error();
228228
}
229229
}
230230

source/Tool/ToolMain.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,17 @@ int main(int argc, char const** argv)
170170
{
171171
return clang::mrdox::mrdox_main(argc, argv);
172172
}
173+
catch(clang::mrdox::Exception const& ex)
174+
{
175+
// Any exception derived from Exception should
176+
// be caught and handled, and never make it here.
177+
MRDOX_UNREACHABLE();
178+
}
173179
catch(std::exception const& ex)
174180
{
175-
// Any exception not derived from Error should be
176-
// reported and terminate the process immediately.
181+
// Any exception not derived from Exception which
182+
// makes it here must be reported and terminate the
183+
// process immediately.
177184
clang::mrdox::reportUnhandledException(ex);
178185
return EXIT_FAILURE;
179186
}

0 commit comments

Comments
 (0)