1 /*
2     MIDI Sequencer C++ library
3     Copyright (C) 2006-2021, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5     This library is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 3 of the License, or
8     (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SEQUENCERERROR_H
20 #define SEQUENCERERROR_H
21 
22 #include <exception>
23 #include <QString>
24 #include "macros.h"
25 
26 /**
27  * @file sequencererror.h
28  * SequencerError Exception class
29  */
30 
31 /**
32  * @namespace std
33  * C++ Standard Library namespace
34  *
35  * @class std::exception
36  * Provides consistent interface to handle errors.
37  * @see https://en.cppreference.com/w/cpp/error/exception
38  */
39 
40 namespace drumstick { namespace ALSA {
41 
42 /**
43  * @addtogroup ALSAError ALSA Sequencer Exception
44  * @{
45  *
46  * @class SequencerError
47  * Exception class for ALSA Sequencer errors.
48  * This class is used to report errors from the ALSA sequencer.
49  *
50  * The class SequencerError represents an exception object reported when the
51  * ALSA library returns an error code. It is only used for severe errors.
52  */
53 class DRUMSTICK_EXPORT SequencerError : std::exception
54 {
55 public:
56     /**
57      * Constructor
58      * @param s  Error location
59      * @param rc Numeric error code
60      */
61     SequencerError(QString const& s, int rc);
62 
63     /**
64      * Retrieve a human readable error message
65      * @return human readable error message
66      */
67     virtual const char* what() const noexcept override;
68 
69     /**
70      * Gets the human readable error message from the error code
71      * @return Error message
72      */
73     QString qstrError() const;
74 
75     /**
76      * Gets the numeric error code
77      * @return Error code
78      */
79     int code() const;
80 
81     /**
82      * Gets the location of the error code as provided in the constructor
83      * @return Error location
84      */
85     const QString& location() const;
86 
87 private:
88     QString m_location;
89     int     m_errCode;
90 };
91 
92 /** @} */
93 
94 }} // namespace drumstick::ALSA
95 
96 #endif // SEQUENCERERROR_H
97