@@ -154,6 +154,79 @@ MCErrorCreateWithMessage (MCTypeInfoRef p_typeinfo,
154154 return true ;
155155}
156156
157+ MC_DLLEXPORT_DEF
158+ bool MCErrorCreateWithMessageV (MCErrorRef& r_error,
159+ MCTypeInfoRef p_error_type,
160+ MCStringRef p_message,
161+ va_list p_args)
162+ {
163+ __MCAssertIsErrorTypeInfo (p_error_type);
164+ __MCAssertIsString (p_message);
165+ MCAutoArrayRef t_info;
166+ if (!MCArrayCreateMutable (&t_info))
167+ return false ;
168+
169+ for (;;)
170+ {
171+ const char *t_key;
172+ t_key = va_arg (p_args, const char *);
173+ if (t_key == nil)
174+ break ;
175+
176+ MCValueRef t_value;
177+ t_value = va_arg (p_args, MCValueRef);
178+
179+ // If a value is nil, then it means don't include it.
180+ if (t_value == nil)
181+ continue ;
182+
183+ MCNewAutoNameRef t_name;
184+ if (!MCNameCreateWithNativeChars ((const char_t *)t_key,
185+ strlen (t_key),
186+ &t_name))
187+ return false ;
188+
189+ if (!MCArrayStoreValue (*t_info,
190+ true ,
191+ *t_name,
192+ t_value))
193+ {
194+ return false ;
195+ }
196+ }
197+
198+ if (!MCErrorCreateWithMessage (p_error_type,
199+ p_message,
200+ *t_info,
201+ r_error))
202+ {
203+ return false ;
204+ }
205+
206+ return true ;
207+ }
208+
209+ MC_DLLEXPORT_DEF
210+ bool MCErrorCreateWithMessageS (MCErrorRef& r_error,
211+ MCTypeInfoRef p_error_type,
212+ MCStringRef p_message,
213+ ...)
214+ {
215+ va_list t_args;
216+ va_start (t_args, p_message);
217+
218+ bool t_result;
219+ t_result = MCErrorCreateWithMessageV (r_error,
220+ p_error_type,
221+ p_message,
222+ t_args);
223+
224+ va_end (t_args);
225+
226+ return t_result;
227+
228+ }
229+
157230MC_DLLEXPORT_DEF
158231bool MCErrorCreate (MCTypeInfoRef p_typeinfo, MCArrayRef p_info, MCErrorRef& r_error)
159232{
@@ -163,6 +236,35 @@ bool MCErrorCreate(MCTypeInfoRef p_typeinfo, MCArrayRef p_info, MCErrorRef& r_er
163236 r_error);
164237}
165238
239+ MC_DLLEXPORT_DEF
240+ bool MCErrorCreateV (MCErrorRef& r_error,
241+ MCTypeInfoRef p_typeinfo,
242+ va_list p_args)
243+ {
244+ return MCErrorCreateWithMessageV (r_error,
245+ p_typeinfo,
246+ MCErrorTypeInfoGetMessage (p_typeinfo),
247+ p_args);
248+ }
249+
250+ MC_DLLEXPORT_DEF
251+ bool MCErrorCreateS (MCErrorRef& r_error,
252+ MCTypeInfoRef p_typeinfo,
253+ ...)
254+ {
255+ va_list t_args;
256+ va_start (t_args, p_typeinfo);
257+
258+ bool t_result;
259+ t_result = MCErrorCreateV (r_error,
260+ p_typeinfo,
261+ t_args);
262+
263+ va_end (t_args);
264+
265+ return t_result;
266+ }
267+
166268MC_DLLEXPORT_DEF
167269bool MCErrorUnwind (MCErrorRef p_error, MCValueRef p_target, uindex_t p_row, uindex_t p_column)
168270{
@@ -325,38 +427,16 @@ MCErrorCreateAndThrowWithMessageV (MCTypeInfoRef p_error_type,
325427 MCStringRef p_message,
326428 va_list p_args)
327429{
328- __MCAssertIsErrorTypeInfo (p_error_type);
329- __MCAssertIsString (p_message);
330- MCAutoArrayRef t_info;
331- if (!MCArrayCreateMutable (&t_info))
332- return false ;
333-
334- for (;;)
335- {
336- const char *t_key;
337- t_key = va_arg (p_args, const char *);
338- if (t_key == nil)
339- break ;
340-
341- MCValueRef t_value;
342- t_value = va_arg (p_args, MCValueRef);
343-
344- // If a value is nil, then it means don't include it.
345- if (t_value == nil)
346- continue ;
347-
348- MCNewAutoNameRef t_name;
349- if (!MCNameCreateWithNativeChars ((const char_t *)t_key, strlen (t_key), &t_name))
350- return false ;
351-
352- if (!MCArrayStoreValue (*t_info, true , *t_name, t_value))
353- return false ;
354- }
355-
356- MCAutoErrorRef t_error;
357- if (!MCErrorCreateWithMessage (p_error_type, p_message, *t_info, &t_error))
358- return false ;
359-
430+
431+ MCAutoErrorRef t_error;
432+ if (!MCErrorCreateWithMessageV (&t_error,
433+ p_error_type,
434+ p_message,
435+ p_args))
436+ {
437+ return false ;
438+ }
439+
360440 return MCErrorThrow (*t_error);
361441}
362442
0 commit comments