blob: 6f237e64ffb54dd4d3a9bdb98b7cb68f99c41f9d [file] [log] [blame]
Shawn McCarney55f496c2020-04-09 16:19:14 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "exception_utils.hpp"
18
19namespace phosphor::power::regulators::exception_utils
20{
21
22std::vector<std::string> getMessages(const std::exception& e)
23{
24 std::vector<std::string> messages{};
25 internal::getMessages(e, messages);
26 return messages;
27}
28
Shawn McCarney55f496c2020-04-09 16:19:14 -050029namespace internal
30{
31
32void getMessages(const std::exception& e, std::vector<std::string>& messages)
33{
34 // If this exception is nested, get messages from inner exception(s)
35 try
36 {
37 std::rethrow_if_nested(e);
38 }
39 catch (const std::exception& inner)
40 {
41 getMessages(inner, messages);
42 }
43 catch (...)
44 {
45 }
46
47 // Append error message from this exception
48 messages.emplace_back(e.what());
49}
50
51} // namespace internal
52
53} // namespace phosphor::power::regulators::exception_utils