ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
exception.cpp
2
3
4namespace alib::exceptions {
5
7 enumrecords::bootstrap::EnumRecordParser::Get( ERSerializable::EnumElementName );
8 ERSerializable::MinimumRecognitionLength= 0;
10}
11
13 // find pointer to the last entry pointer;
14 detail::ExceptionEntry** tail= &**this;
15 while(*tail != nullptr)
16 tail= &(*tail)->next;
17
18 *tail= GetAllocator()().Alloc<detail::ExceptionEntry>();
19 (*tail)->next= nullptr;
20
21 return &(*tail)->message;
22}
23
24
26 bool hasRecord,
27 ResourcePool* pool,
28 const NString& category ) {
29 message->CloneAll();
30
31 if( hasRecord ) {
32 #if ALIB_DEBUG
33 {
34 auto* tryRecord= boxing::TryRecord<ERException>(message->Type);
35 if( tryRecord == nullptr ) {
36 std::vector<std::pair<integer,const void*>> recordList;
37 for( auto& record : enumrecords::detail::getInternalRecordMap() )
38 if( record.first.RTTI == message->Type.TypeID() )
39 recordList.push_back( std::pair<integer,const void*>(record.first.Element, record.second) );
40 if( recordList.size() == 0) {
41 ALIB_ERROR( "EXCEPT", "No enum records defined for exception enumeration "
42 "type {!Q<>}.", message->Type.TypeID().name() )
43 } else {
44 std::sort( recordList.begin(), recordList.end(),
45 [] ( std::pair<integer,const void*>& a, std::pair<integer,const void*>& b )
46 { return a.first < b.first;});
47 std::vector<std::any> args; args.reserve(32);
48 args.emplace_back( "Enum record {} not found for exception enumeration type {}.\n"
49 "The following records have been found:\n" );
50 args.emplace_back( message->Type.Integral() );
51 args.emplace_back( &message->Type.TypeID() );
52
53 for( auto& pair : recordList ) {
54 args.emplace_back( " {}: {}\n" );
55 args.emplace_back( pair.first );
56 args.emplace_back( reinterpret_cast<const ERException*>( pair.second )->EnumElementName );
57 }
58 assert::raise( ALIB_CALLER_PRUNED, 1, "EXCEPT", args );
59 } } }
60 #endif
61 const auto& enumRecord= boxing::GetRecord<ERException>(message->Type);
62 if( pool == nullptr )
63 message->emplace( message->begin(),
64 enumRecord.DescriptionOrItsResourceName );
65 else
66 message->emplace( message->begin(),
67 pool->Get( category,
68 enumRecord.DescriptionOrItsResourceName
69 ALIB_DBG(, true) ) );
70} }
71
72
74 auto* result= **this;
75 while( result->next != nullptr )
76 result= result->next;
77
78 return result->message;
79}
80
81int Exception::Size() const {
82 int result= 1;
83 auto* entry= **this;
84 while( entry->next != nullptr ) {
85 entry= entry->next;
86 ++result;
87 }
88
89 return result;
90}
91
92const Enum& Exception::Type() const {
93 auto* entry= **this;
94 Enum* result= &entry->message.Type;
95 while( (entry= entry->next) != nullptr )
96 if( entry->message.Type.Integral() >= 0 )
97 result= &entry->message.Type;
98
99 return *result;
100}
101
102
103#if ALIB_FORMAT
105 Paragraphs text(target);
106 Tokenizer tknzr;
107 tknzr.TrimChars= A_CHAR( "\r" );
108 String1K buf;
110 Formatter& formatter= *Formatter::DEFAULT;
112 formatter.GetArgContainer();
113 size_t entryNo= 1;
114 for ( auto entryIt= begin(); entryIt != end(); ++entryIt ) {
115 text.Add( A_CHAR("{}{}: {!Q<>}"), (entryIt->Type.Integral() >= 0 ? 'E' : 'I'), entryNo, entryIt->Type );
116 text.PushIndent( A_CHAR(" ") );
117 try
118 {
119 formatter.FormatArgs( buf.Reset(), *entryIt );
120 }
121 catch( Exception& e )
122 {
123 #if ALIB_CAMP
124 buf << BASECAMP.GetResource("ExcFmtExc");
125 #else
126 buf << A_CHAR("\nAn exception occurred while formatting another (!) exception:\n" );
127 #endif
128 e.Format( buf );
129 }
130 tknzr.Set( buf, '\n' );
131 while( tknzr.HasNext() )
132 text.Add( tknzr.Next() );
133
134 #if ALIB_DEBUG
135 text.Add( entryIt->CI );
136 #endif
137
138 text.PopIndent();
139 ++entryNo;
140 }
141
142 return target;
143}
144#endif // ALIB_FORMAT
145
146} // namespace [alib::lang]
#define A_CHAR(STR)
#define ALIB_ERROR(domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_DBG(...)
#define ALIB_CALLER_PRUNED
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
AString & Format(AString &target) const
Message & Back() const
Definition exception.cpp:73
ForwardIterator begin()
const Enum & Type() const
Definition exception.cpp:92
void finalizeMessage(Message *message, bool hasRecord, ResourcePool *pool, const NString &category)
Definition exception.cpp:25
Exception(const Exception &) noexcept=default
Deleted copy constructor. Exceptions must be caught only as references.
static threads::RecursiveLock DEFAULT_LOCK
static SPFormatter DEFAULT
Paragraphs & PushIndent(uinteger qty, character fillChar=' ')
void Add(boxing::TBoxes< TAllocatorArgs > &args)
Paragraphs & PopIndent()
virtual const String & Get(const NString &category, const NString &name, bool dbgAssert)=0
void DbgDisableBufferReplacementWarning()
Definition tastring.hpp:236
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
Definition tokenizer.cpp:4
TLocalString< TChar, 8 > TrimChars
Definition tokenizer.hpp:68
void raise(const CallerInfo &ci, int type, std::string_view domain, const std::span< std::any > &args)
Definition assert.cpp:552
const TRecord * TryRecord(Enum e)
const TRecord & GetRecord(Enum e)
HashMap< MonoAllocator, EnumRecordKey, const void *, EnumRecordKey::Hash, EnumRecordKey::EqualTo > & getInternalRecordMap()
Definition records.cpp:50
Definition alox.cpp:14
strings::TString< nchar > NString
Type alias in namespace #"%alib".
Definition string.hpp:2174
format::Formatter Formatter
Type alias in namespace #"%alib".
resources::ResourcePool ResourcePool
Type alias in namespace #"%alib".
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace #"%alib".
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class #"Basecamp".
Definition basecamp.cpp:2
LocalString< 1024 > String1K
Type alias name for #"TLocalString;TLocalString<character,1024>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
format::Paragraphs Paragraphs
Type alias in namespace #"%alib".
boxing::Enum Enum
Type alias in namespace #"%alib".
Definition enum.hpp:210
TIntegral Integral() const
Definition enum.hpp:87
const std::type_info & TypeID() const
Definition box.hpp:759
String EnumElementName
The name of the enum element.
Definition records.hpp:423
static void Get(String &result, bool isLastField=false)
ExceptionEntry * next
A pointer to the next message.
Definition exception.hpp:19