aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/error.h
blob: fcf345143cc085cb4e75d8e24805ed18aa692d95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "common.h"

#ifdef Error
#undef Error
#endif

namespace mbus {

/**
 * An Error contains an error code (@ref ErrorCode) combined with an
 * error message.
 **/
class Error
{
private:
    uint32_t  _code;
    string    _msg;
    string    _service;

public:
    /**
     * Create an error with error code NONE and an empty message. This
     * constructor is not intended for application use, but is needed
     * for standard library containers.
     **/
    Error();
    ~Error();

    /**
     * Create a new error with the given code and message
     *
     * @param c error code
     * @param m error message
     * @param s error service
     **/
    Error(uint32_t c, vespalib::stringref m, vespalib::stringref s = "");

    /**
     * Obtain the error code of this error.
     *
     * @return error code
     **/
    uint32_t getCode() const { return _code; }

    /**
     * Obtain the error message of this error.
     *
     * @return error message
     **/
    const string &getMessage() const { return _msg; }

    /**
     * Obtain the service string of this error.
     *
     * @return service string
     **/
    const string &getService() const { return _service; }

    /**
     * Obtain a string representation of this error.
     *
     * @return string representation
     **/
    string toString() const;
};

} // namespace mbus