⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exc.cpp

📁 伯克利做的SFTP安全文件传输协议
💻 CPP
字号:
// exc.cc// code for exc.h// SafeTP project// copyright SafeTP Development Group, Inc., 2000  Terms of use are as specified in license.txt#include "exc.h"          // this module#include <string.h>       // strlen, strcpy#include <iostream.h>     // clog#include <stdarg.h>       // va_xxx#include <ctype.h>        // toupper, tolower// ------------------------- xBase -----------------// thread safety: this is presumed only changed during global initbool xBase::logExceptions = true;// thread safety: depends.. if x86 'inc' and 'dec' are used to manipulate// it, it's safe for a uniprocessor.. otherwise it's not, though// exceptions are a relatively rare occurance.. and it only affects// the behavior of CAUTIOUS_UNWIND, which is itself relatively rare.. so// perhaps it's better to leave this unprotected than to introduce a// dependency on nonport.h ...int xBase::creationCount = 0;xBase::xBase(char const *m)  : msg(m){  if (logExceptions) {    clog << "Exception thrown: " << m << endl;  }  // done at very end when we know this object will  // successfully be created  creationCount++;}xBase::xBase(xBase const &obj)  : msg(obj.msg){  creationCount++;}xBase::~xBase(){  creationCount--;}// this is obviously not perfect, since exception objects can be// created and not thrown; I heard the C++ standard is going to,// or already does, include (by this name?) a function that does this// correctly; until then, this will serve as a close approximation// (this kind of test is, IMO, not a good way to handle the underlying// problem, but it does reasonably handle 70-90% of the cases that// arise in practice, so I will endorse it for now)bool unwinding(){  return xBase::creationCount != 0;}// tweaked versionbool unwinding_other(xBase const &){  // we know the passed xBase exists.. any others?  return xBase::creationCount > 1;}void xBase::insert(ostream &os) const{  os << why();}// ------------------- x_assert -----------------x_assert::x_assert(char const *cond, char const *fname, int line)  : xBase(stringb(      "Assertion failed: " << cond <<      ", file " << fname <<      " line " << line)),    condition(cond),    filename(fname),    lineno(line){}x_assert::x_assert(x_assert const &obj)  : xBase(obj),    condition(obj.condition),    filename(obj.filename),    lineno(obj.lineno){}x_assert::~x_assert(){}// failure function, declared in xassert.hvoid x_assert_fail(char const *cond, char const *file, int line){  THROW(x_assert(cond, file, line));}// --------------- xFormat ------------------xFormat::xFormat(char const *cond)  : xBase(stringb("Formatting error: " << cond)),    condition(cond){}xFormat::xFormat(xFormat const &obj)  : xBase(obj),    condition(obj.condition){}xFormat::~xFormat(){}void xformat(char const *condition){  xFormat x(condition);  THROW(x);}// ---------------- test code ------------------#ifdef TEST_EXCint main(){  xBase x("yadda");  cout << x << endl;  try {    THROW(x);  }  catch (xBase &x) {    cout << "caught xBase: " << x << endl;  }  return 0;}#endif // TEST_EXC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -