Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit cc82dd8

Browse files
committed
[[ FoundationError ]] Added generic runtime error and MCErrorThrowGeneric.
1 parent 2934db9 commit cc82dd8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

libfoundation/include/foundation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,6 +2168,7 @@ bool MCRecordStoreValue(MCRecordRef record, MCNameRef field, MCValueRef value);
21682168
//
21692169

21702170
extern MCTypeInfoRef kMCOutOfMemoryErrorTypeInfo;
2171+
extern MCTypeInfoRef kMCGenericErrorTypeInfo;
21712172

21722173
bool MCErrorCreate(MCTypeInfoRef typeinfo, MCArrayRef info, MCErrorRef& r_error);
21732174

@@ -2197,6 +2198,9 @@ MCErrorRef MCErrorPeek(void);
21972198
// Throw an out of memory error.
21982199
bool MCErrorThrowOutOfMemory(void);
21992200

2201+
// Throw a generic runtime error (one that hasn't had a class made for it yet).
2202+
bool MCErrorThrowGeneric(void);
2203+
22002204
////////////////////////////////////////////////////////////////////////////////
22012205
//
22022206
// STREAM DEFINITIONS

libfoundation/src/foundation-error.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2121
////////////////////////////////////////////////////////////////////////////////
2222

2323
MCTypeInfoRef kMCOutOfMemoryErrorTypeInfo;
24+
MCTypeInfoRef kMCGenericErrorTypeInfo;
2425

2526
static MCErrorRef s_last_error = nil;
2627

@@ -115,11 +116,24 @@ bool MCErrorThrowOutOfMemory(void)
115116
}
116117

117118
MCErrorThrow(s_out_of_memory_error);
119+
MCValueRelease(s_out_of_memory_error);
118120
s_out_of_memory_error = nil;
119121

120122
return false;
121123
}
122124

125+
bool MCErrorThrowGeneric(void)
126+
{
127+
MCErrorRef t_error;
128+
if (!MCErrorCreate(kMCGenericErrorTypeInfo, nil, t_error))
129+
return false;
130+
131+
MCErrorThrow(t_error);
132+
MCValueRelease(t_error);
133+
134+
return false;
135+
}
136+
123137
////////////////////////////////////////////////////////////////////////////////
124138

125139
void __MCErrorDestroy(__MCError *self)
@@ -151,6 +165,12 @@ bool __MCErrorInitialize(void)
151165
return false;
152166
if (!MCTypeInfoBindAndRelease(MCNAME("livecode.lang.OutOfMemoryError"), kMCOutOfMemoryErrorTypeInfo, kMCOutOfMemoryErrorTypeInfo))
153167
return false;
168+
169+
if (!MCErrorTypeInfoCreate(MCNAME("runtime"), MCSTR("unknown"), kMCGenericErrorTypeInfo))
170+
return false;
171+
if (!MCTypeInfoBindAndRelease(MCNAME("livecode.lang.GenericError"), kMCGenericErrorTypeInfo, kMCOutOfMemoryErrorTypeInfo))
172+
return false;
173+
154174
if (!MCErrorCreate(kMCOutOfMemoryErrorTypeInfo, nil, s_out_of_memory_error))
155175
return false;
156176

0 commit comments

Comments
 (0)