1 /* 2 * Copyright 2021 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _ERRORS_EXT_H 6 #define _ERRORS_EXT_H 7 8 #include <iosfwd> 9 10 #include <String.h> 11 #include <SupportDefs.h> 12 13 class BDataIO; 14 15 16 namespace BPrivate { 17 18 namespace Network { 19 20 21 class BError 22 { 23 public: 24 BError(const char* origin); 25 BError(BString origin); 26 virtual ~BError() noexcept; 27 28 BError(const BError& error); 29 BError(BError&& error) noexcept; 30 31 BError& operator=(const BError& error); 32 BError& operator=(BError&& error) noexcept; 33 34 virtual const char* Message() const noexcept = 0; 35 virtual const char* Origin() const noexcept; 36 virtual BString DebugMessage() const; 37 void WriteToStream(std::ostream& stream) const; 38 size_t WriteToOutput(BDataIO* output) const; 39 40 private: 41 virtual void _ReservedError1(); 42 virtual void _ReservedError2(); 43 virtual void _ReservedError3(); 44 virtual void _ReservedError4(); 45 46 private: 47 BString fOrigin; 48 }; 49 50 51 class BRuntimeError : public BError 52 { 53 public: 54 BRuntimeError(const char* origin, const char* message); 55 BRuntimeError(const char* origin, BString message); 56 BRuntimeError(BString origin, BString message); 57 58 BRuntimeError(const BRuntimeError& other); 59 BRuntimeError(BRuntimeError&& other) noexcept; 60 61 BRuntimeError& operator=(const BRuntimeError& other); 62 BRuntimeError& operator=(BRuntimeError&& other) noexcept; 63 64 virtual const char* Message() const noexcept override; 65 66 private: 67 BString fMessage; 68 }; 69 70 71 class BSystemError : public BError 72 { 73 public: 74 BSystemError(const char* origin, status_t error); 75 BSystemError(BString origin, status_t error); 76 77 BSystemError(const BSystemError& other); 78 BSystemError& operator=(const BSystemError& other); 79 80 BSystemError(BSystemError&& other) noexcept; 81 BSystemError& operator=(BSystemError&& other) noexcept; 82 83 virtual const char* Message() const noexcept override; 84 virtual BString DebugMessage() const override; 85 status_t Error() noexcept; 86 87 private: 88 status_t fErrorCode; 89 }; 90 91 } // namespace Network 92 93 } // Namespace BPrivate 94 95 #endif // _ERRORS_EXT_H 96