projects/guix·blob java-team · refs

90 lines · 2.0 KiB

1#pragma once
2
3#include "config.h"
4
5#include <string>
6#include <list>
7#include <set>
8#include <vector>
9#include <string_view>
10
11
12/* Before 4.7, gcc's std::exception uses empty throw() specifiers for
13 * its (virtual) destructor and what() in c++11 mode, in violation of spec
14 */
15#ifdef __GNUC__
16#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
17#define EXCEPTION_NEEDS_THROW_SPEC
18#endif
19#endif
20
21
22namespace nix {
23
24
25/* Inherit some names from other namespaces for convenience. */
26using std::string;
27using std::list;
28using std::set;
29using std::vector;
30
31
32/* BaseError should generally not be caught, as it has Interrupted as
33 a subclass. Catch Error instead. */
34class BaseError : public std::exception
35{
36protected:
37 string prefix_; // used for location traces etc.
38 string err;
39public:
40 unsigned int status; // exit status
41 BaseError(std::string_view fs, unsigned int status = 1);
42#ifdef EXCEPTION_NEEDS_THROW_SPEC
43 ~BaseError() throw () { };
44 const char * what() const throw () { return err.c_str(); }
45#else
46 const char * what() const noexcept { return err.c_str(); }
47#endif
48 const string & msg() const { return err; }
49 const string & prefix() const { return prefix_; }
50 BaseError & addPrefix(std::string fs);
51};
52
53#define MakeError(newClass, superClass) \
54 class newClass : public superClass \
55 { \
56 public: \
57 newClass(std::string_view fs, unsigned int status = 1) : superClass(fs, status) { }; \
58 };
59
60MakeError(Error, BaseError)
61
62class SysError : public Error
63{
64public:
65 int errNo;
66 SysError(std::string_view fs);
67};
68
69
70using Strings = std::list<std::string>;
71using StringSet = std::set<std::string>;
72
73
74/* Paths are just strings. */
75using Path = std::string;
76using Paths = std::list<Path>;
77using PathSet = std::set<Path>;
78
79
80enum Verbosity {
81 lvlError = 0,
82 lvlInfo,
83 lvlTalkative,
84 lvlChatty,
85 lvlDebug,
86 lvlVomit
87};
88
89
90}