blob: 81d700b789793908a78a157838f1c96ea9b86788 [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#pragma once
17
18#include "journal.hpp"
19
20#include <exception>
21#include <string>
22#include <vector>
23
24/**
25 * @namespace exception_utils
26 *
27 * Contains utility functions for handling exceptions.
28 */
29namespace phosphor::power::regulators::exception_utils
30{
31
32/**
33 * Gets the error messages from the specified exception and any nested inner
34 * exceptions.
35 *
36 * If the exception contains nested inner exceptions, the messages in the
37 * returned vector will be ordered from innermost exception to outermost
38 * exception.
39 *
40 * @param e exception
41 * @return error messages from exceptions
42 */
43std::vector<std::string> getMessages(const std::exception& e);
44
Shawn McCarney55f496c2020-04-09 16:19:14 -050045/*
46 * Internal implementation details
47 */
48namespace internal
49{
50
51/**
52 * Gets the error messages from the specified exception and any nested inner
53 * exceptions.
54 *
55 * Stores the error messages in the specified vector, from innermost exception
56 * to outermost exception.
57 *
58 * @param e exception
59 * @param messages vector where error messages will be stored
60 */
61void getMessages(const std::exception& e, std::vector<std::string>& messages);
62
63} // namespace internal
64
65} // namespace phosphor::power::regulators::exception_utils