Vuo  2.4.0
VuoException.cc
Go to the documentation of this file.
1
10#include "VuoException.hh"
11
12#include <iostream>
13#include <sstream>
14
15using namespace std;
16
22VuoException::VuoException(const string &description, bool log)
23{
24 this->description = description;
25 this->backtrace = VuoLog_getBacktrace();
26
27 if (log)
28 {
29 if (backtrace.size() < 3)
30 {
31 VUserLog("%s", description.c_str());
32 return;
33 }
34
35 ostringstream oss;
36 oss << description << endl;
37 oss << "Exception occurred at:" << endl;
38
39 // Skip the VuoException constructor.
40 backtrace.erase(backtrace.begin());
41
42 int i = 1;
43 for (auto line : backtrace)
44 {
45 char *lineNumber;
46 asprintf(&lineNumber, "%3d ", i++);
47 oss << lineNumber << line << endl;
48 free(lineNumber);
49 }
50
51 string dispatchQueue = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
52 if (dispatchQueue != "com.apple.root.default-qos")
53 oss << "Queue: " << dispatchQueue << endl;
54
55 char threadName[256];
56 bzero(threadName, 256);
57 int ret = pthread_getname_np(pthread_self(), threadName, 256);
58 if (ret == 0 && strlen(threadName))
59 oss << "Thread: " << threadName << endl;
60
61 // Use VLog so it appears in crash reports.
62 VUserLog("%s", oss.str().c_str());
63 }
64}
65
70{
71}
72
76const char *VuoException::what() const throw()
77{
78 return description.c_str();
79}
80
84const vector<string> &VuoException::getBacktrace()
85{
86 return backtrace;
87}