📄 exception.c
字号:
//// Implemention of thread exceptions.#include "thread.h"#include "stack.h"#include "exception.h"#include <iostream>#include <cstring>namespace cpp_threads { exception::exception(const std::string& pMessage,tType pType) { mTextMessage = pMessage; mErrorKind = pType; mErrno = -1; mState = false; if ( pType == ex_fatal ) throw *this; } exception::~exception() throw() { } void exception::setMessage(const std::string& pMessage) { mTextMessage = pMessage; } const char * exception::what() { return mTextMessage.c_str(); } std::string exception::message() const { return mTextMessage; } exception::tType exception::severity() { return mErrorKind; } int exception::error() { return mErrno; } void exception::setException(tType pKind) { if( mState ) return; mState = true; mErrorKind = pKind; if( pKind != ex_fatal ) { Pthread *th = Pthread::self(); if( th && th->stack() ) { if( th->stack()->getcontext() == false ) throw *this; } else throw *this; } else throw *this; mState = false; } void exception::setError(int pErrno) { mErrno = pErrno; if( mState && mErrno == 0 ) { Pthread *th = Pthread::self(); if( th && th->stack() ) th->stack()->setcontext(); } } void exception::staticException(const std::string& pMessage,tType pKind) { exception *e; e = new exception(pMessage,ex_none); e->setException(pKind); delete e; } void exception::staticException(int pErrno,tType pKind) { exception *e; e = new exception( strerror(pErrno),ex_none ); e->setError( pErrno ); e->setException( pKind ); delete e; }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -