aboutsummaryrefslogtreecommitdiff
path: root/c/data.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-22 01:02:34 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-22 01:02:34 +0200
commit28b87e4d9c60b49d46b03a19b7b83e23e222087a (patch)
tree1f0a71ca09f04eac51fdabf2e8cfabc87a6e02a3 /c/data.cpp
parent801c10f07d1c92e1b1b89d8a30cb0cf86745de31 (diff)
downloadEpisodeBrowser-28b87e4d9c60b49d46b03a19b7b83e23e222087a.tar.gz
Handle exceptions in fetching thread.
Diffstat (limited to 'c/data.cpp')
-rw-r--r--c/data.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/c/data.cpp b/c/data.cpp
index 4bded44..771e6fb 100644
--- a/c/data.cpp
+++ b/c/data.cpp
@@ -70,7 +70,7 @@ static inline void XmlFree(void* p) { xmlFree(p); }
using XmlCharPtr = XmlPtr<XmlFree, xmlChar*>;
template <size_t N>
-bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8)
+bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8) noexcept
{
/* Truncate if source is larger than destination. */
int lenUtf8 = xmlStrlen(utf8);
@@ -94,7 +94,7 @@ bool WcharsFromXmlchars(wchar_t (&dst)[N], XmlCharPtr utf8)
return MultiByteToWideChar(CP_UTF8, 0, src, cchNarrow, dst, cchWide);
}
-void FetchData(bool* bDone)
+void FetchData()
{
LIBXML_TEST_VERSION;
@@ -123,7 +123,9 @@ void FetchData(bool* bDone)
xmlNodeSetPtr nodes = xpathObj->nodesetval;
int cNodes = nodes? nodes->nodeNr: 0;
- printf("%d nodes\n", cNodes);
+ if (!cNodes)
+ throw std::runtime_error("could not find remote episode information");
+
for (int i = 0; i < cNodes; i++) {
extern FileView<ElvDataA> g_fvElv;
extern FileView<DlvDataA> g_fvDlv;
@@ -153,8 +155,18 @@ void FetchData(bool* bDone)
/* Get wiki URL. */
const xmlNodePtr nodeLink = xmlFirstElementChild(nodeTitle);
if (nodeLink)
- WcharsFromXmlchars(d.wiki, xmlGetProp(nodeLink, (const xmlChar*)"href"));
+ WcharsFromXmlchars(d.wiki,
+ xmlGetProp(nodeLink, reinterpret_cast<const xmlChar*>("href")));
}
+}
- *bDone = true;
+void WaitFetchData(bool* bDone) noexcept
+{
+ try {
+ FetchData();
+ *bDone = true;
+ } catch (...) {
+ *bDone = true;
+ ShowException(L"Remote data could not be fetched due to %s: %s", L"Error", MB_ICONWARNING);
+ }
}