File tree 6 files changed +52
-66
lines changed
6 files changed +52
-66
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,14 @@ class [[nodiscard]] MRDOX_DECL
119
119
source_location loc =
120
120
source_location::current ());
121
121
122
+ /* * Constructor.
123
+
124
+ The constructed object will always
125
+ indicate a failure, even if the message
126
+ in the exception is empty.
127
+ */
128
+ explicit Error (std::exception const & ex);
129
+
122
130
/* * Constructor.
123
131
124
132
This constructs a new error from a list
@@ -889,16 +897,6 @@ fatal(
889
897
890
898
} // report
891
899
892
- // ------------------------------------------------
893
-
894
- /* * Report an unhandled exception
895
- */
896
- MRDOX_DECL
897
- [[noreturn]]
898
- void
899
- reportUnhandledException (
900
- std::exception const & ex);
901
-
902
900
} // mrdox
903
901
} // clang
904
902
Original file line number Diff line number Diff line change @@ -80,6 +80,17 @@ Error(
80
80
loc_ = loc;
81
81
}
82
82
83
+ Error::
84
+ Error (
85
+ std::exception const & ex)
86
+ {
87
+ std::string_view s (ex.what ());
88
+ if (s.empty ())
89
+ s = " unknown exception" ;
90
+ reason_ = s;
91
+ message_ = s;
92
+ }
93
+
83
94
Error::
84
95
Error (
85
96
std::vector<Error> const & errors,
@@ -224,20 +235,5 @@ call_impl(
224
235
225
236
} // report
226
237
227
- // ------------------------------------------------
228
-
229
- void
230
- reportUnhandledException (
231
- std::exception const & ex)
232
- {
233
- namespace sys = llvm::sys;
234
-
235
- std::lock_guard<llvm::sys::Mutex> lock (reportMutex_);
236
- llvm::errs () <<
237
- " Unhandled exception: " << ex.what () << ' \n ' ;
238
- sys::PrintStackTrace (llvm::errs ());
239
- std::exit (EXIT_FAILURE);
240
- }
241
-
242
238
} // mrdox
243
239
} // clang
Original file line number Diff line number Diff line change @@ -125,11 +125,8 @@ run(std::unique_lock<std::mutex> lock)
125
125
}
126
126
catch (std::exception const & ex)
127
127
{
128
- // Any exception which is not
129
- // derived from Exception should
130
- // be reported and terminate
131
- // the process immediately.
132
- reportUnhandledException (ex);
128
+ lock.lock ();
129
+ impl_->errors .emplace (Error (ex));
133
130
}
134
131
}
135
132
}
Original file line number Diff line number Diff line change @@ -75,26 +75,14 @@ post(
75
75
[sp = std::make_shared<
76
76
any_callable<void (void )>>(std::move (f))]
77
77
{
78
- try
79
- {
80
- (*sp)();
81
- }
82
- catch (std::exception const & ex)
83
- {
84
- reportUnhandledException (ex);
85
- }
78
+ // do NOT catch exceptions here
79
+ (*sp)();
86
80
});
87
81
return ;
88
82
}
89
83
90
- try
91
- {
92
- f ();
93
- }
94
- catch (std::exception const & ex)
95
- {
96
- reportUnhandledException (ex);
97
- }
84
+ // do NOT catch exceptions here
85
+ f ();
98
86
}
99
87
100
88
// ------------------------------------------------
@@ -180,11 +168,8 @@ post(
180
168
}
181
169
catch (std::exception const & ex)
182
170
{
183
- // Any exception which is not
184
- // derived from Error should
185
- // be reported and terminate
186
- // the process immediately.
187
- reportUnhandledException (ex);
171
+ std::lock_guard<std::mutex> lock (impl_->mutex );
172
+ impl_->errors .emplace (Error (ex));
188
173
}
189
174
});
190
175
return ;
@@ -200,9 +185,8 @@ post(
200
185
}
201
186
catch (std::exception const & ex)
202
187
{
203
- reportUnhandledException (ex );
188
+ impl_-> errors . emplace ( Error (ex) );
204
189
}
205
- return ;
206
190
}
207
191
208
192
} // mrdox
Original file line number Diff line number Diff line change @@ -92,6 +92,16 @@ int test_main(int argc, char const* const* argv)
92
92
return EXIT_SUCCESS;
93
93
}
94
94
95
+ static void reportUnhandledException (
96
+ std::exception const & ex)
97
+ {
98
+ namespace sys = llvm::sys;
99
+
100
+ llvm::errs () <<
101
+ " Unhandled exception: " << ex.what () << ' \n ' ;
102
+ sys::PrintStackTrace (llvm::errs ());
103
+ }
104
+
95
105
} // mrdox
96
106
} // clang
97
107
@@ -103,16 +113,12 @@ int main(int argc, char** argv)
103
113
}
104
114
catch (clang::mrdox::Exception const & ex)
105
115
{
106
- // Any exception derived from Exception should
107
- // be caught and handled, and never make it here.
116
+ // thrown Exception should never get here.
108
117
clang::mrdox::reportUnhandledException (ex);
109
- return EXIT_FAILURE;
110
118
}
111
119
catch (std::exception const & ex)
112
120
{
113
- // Any exception not derived from Exception which
114
- // makes it here must be reported and exit the program.
115
121
clang::mrdox::reportUnhandledException (ex);
116
- return EXIT_FAILURE;
117
122
}
123
+ return EXIT_FAILURE;
118
124
}
Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ int mrdox_main(int argc, char const** argv)
82
82
return EXIT_SUCCESS;
83
83
}
84
84
85
+ static void reportUnhandledException (
86
+ std::exception const & ex)
87
+ {
88
+ namespace sys = llvm::sys;
89
+
90
+ llvm::errs () <<
91
+ " Unhandled exception: " << ex.what () << ' \n ' ;
92
+ sys::PrintStackTrace (llvm::errs ());
93
+ }
94
+
85
95
} // mrdox
86
96
} // clang
87
97
@@ -93,17 +103,12 @@ int main(int argc, char const** argv)
93
103
}
94
104
catch (clang::mrdox::Exception const & ex)
95
105
{
96
- // Any exception derived from Exception should
97
- // be caught and handled, and never make it here.
106
+ // thrown Exception should never get here.
98
107
clang::mrdox::reportUnhandledException (ex);
99
- MRDOX_UNREACHABLE ();
100
108
}
101
109
catch (std::exception const & ex)
102
110
{
103
- // Any exception not derived from Exception which
104
- // makes it here must be reported and terminate the
105
- // process immediately.
106
111
clang::mrdox::reportUnhandledException (ex);
107
- return EXIT_FAILURE;
108
112
}
113
+ return EXIT_FAILURE;
109
114
}
You can’t perform that action at this time.
0 commit comments