-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.hpp
More file actions
61 lines (51 loc) · 1.69 KB
/
exception.hpp
File metadata and controls
61 lines (51 loc) · 1.69 KB
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
#pragma once
#ifndef LIBFTPP_EXCEPTION_HPP
# define LIBFTPP_EXCEPTION_HPP
# include "libftpp/optional.hpp"
# include "libftpp/source_location.hpp"
# include <exception>
# include <string>
namespace ft {
/**
* @brief Exception class with context information
*
* The class inherits from `std::exception`, so it can be caught as such.
*
* @note All non-standard exception classes in libftpp inherit from this class.
*/
class exception : public std::exception {
public:
explicit exception(const std::string& error);
exception(const std::string& error, const ft::source_location& where);
exception(const std::string& error, const std::string& who);
exception(const std::string& error,
const ft::source_location& where,
const std::string& who);
exception(const exception& other) throw();
virtual ~exception() throw();
exception& operator=(exception other) throw();
/**
* @return An error message in the following format:
* `[where().format(): ][who(): ]<error()>`
*/
const char* what() const throw();
void swap(exception& other) throw();
exception& set_where(const ft::source_location& where);
exception& set_who(const std::string& who);
/**
* @return The unformatted error message, not including information from
* `where()` and `who()`
*/
const std::string& error() const throw();
const ft::optional<ft::source_location>& where() const throw();
const ft::optional<std::string>& who() const throw();
private:
void _update_what_output();
std::string _what_output;
std::string _error;
ft::optional<ft::source_location> _where;
ft::optional<std::string> _who;
};
void swap(exception& lhs, exception& rhs) throw();
} // namespace ft
#endif // LIBFTPP_EXCEPTION_HPP