-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRBException.cpp
52 lines (41 loc) · 1.52 KB
/
RBException.cpp
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
/*
* RBException.cpp
* PlayerKit
*
* Created by Peter MacWhinnie on 5/18/09.
* Copyright 2009 Roundabout Software. All rights reserved.
*
*/
#include "RBException.h"
#include <iostream>
CFStringRef RBException::InternalInconsistencyDomain = CFSTR("InternalInconsistencyDomain");
void RBException::HandleFailureInFunction(const char *function, const char *file, int lineNumber, OSStatus erorrCode, CFStringRef description, ...)
{
va_list format;
va_start(format, description);
CFStringRef reason = CFStringCreateWithFormatAndArguments(kCFAllocatorDefault, NULL, description, format);
va_end(format);
fprintf(stderr, "*** Assertion failure in function %s in file %s on line %d with reason ", function, file, lineNumber);
//CFString does not like to be converted to a C String, so we
//output it using the CoreFoundation mechanism for doing so.
CFShow(reason);
fprintf(stderr, "\n");
RBException exception(RBException::InternalInconsistencyDomain, reason, erorrCode);
//`exception` is taking ownership
CFRelease(reason);
#if DEBUG
Debugger();
#endif /* DEBUG */
throw exception;
}
CFErrorRef RBException::CopyError() const
{
const void *keys[] = { kCFErrorLocalizedDescriptionKey };
const void *values[] = { this->GetReason() };
return CFErrorCreateWithUserInfoKeysAndValues(kCFAllocatorDefault, //allocator
this->GetDomain(), //domain
this->GetCode(), //code
keys, //user info keys
values, //user info values
1); //user info pairs count
}