Skip to content
Browse files

threads: add missing exceptions handlers

  • Loading branch information...
1 parent 99d7682 commit c48fcdd0dcd4fff1adffe1a03aee61aa2b7fa995 @FernetMenta committed May 2, 2012
View
4 xbmc/threads/Thread.cpp
@@ -104,9 +104,7 @@ THREADFUNC CThread::staticThread(void* data)
currentThread.set(pThread);
pThread->m_StartEvent.Set();
- pThread->OnStartup();
- pThread->Process();
- pThread->OnExit();
+ pThread->Action();
// lock during termination
CSingleLock lock(pThread->m_CriticalSection);
View
1 xbmc/threads/Thread.h
@@ -115,6 +115,7 @@ class CThread
ThreadIdentifier ThreadId() const;
void SetThreadInfo();
void TermHandler();
+ void Action();
ThreadIdentifier m_ThreadId;
ThreadOpaque m_ThreadOpaque;
View
32 xbmc/threads/platform/pthreads/ThreadImpl.cpp
@@ -229,4 +229,36 @@ float CThread::GetRelativeUsage()
return m_fLastUsage;
}
+void CThread::Action()
+{
+ try
+ {
+ OnStartup();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete());
+ if (IsAutoDelete())
+ return;
+ }
+
+ try
+ {
+ Process();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete());
+ }
+
+ try
+ {
+ OnExit();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread exit, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete());
+ }
+}
+
View
50 xbmc/threads/platform/win/ThreadImpl.cpp
@@ -20,6 +20,7 @@
*/
#include <windows.h>
+#include "utils/Win32Exception.h"
void CThread::Create(bool bAutoDelete, unsigned stacksize)
@@ -190,3 +191,52 @@ float CThread::GetRelativeUsage()
return m_fLastUsage;
}
+
+void CThread::Action()
+{
+ // install win32 exception translator
+ win32_exception::install_handler();
+
+ try
+ {
+ OnStartup();
+ }
+ catch (const access_violation &e)
+ {
+ e.writelog(__FUNCTION__);
+ if (IsAutoDelete())
+ return;
+ }
+ catch (const win32_exception &e)
+ {
+ e.writelog(__FUNCTION__);
+ if (IsAutoDelete())
+ return;
+ }
+
+ try
+ {
+ Process();
+ }
+ catch (const access_violation &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+ catch (const win32_exception &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+
+ try
+ {
+ OnExit();
+ }
+ catch (const access_violation &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+ catch (const win32_exception &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+}

0 comments on commit c48fcdd

Please sign in to comment.
Something went wrong with that request. Please try again.