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

📄 exc.h

📁 伯克利做的SFTP安全文件传输协议
💻 H
字号:
// exc.h// exception classes for SafeTP project// copyright SafeTP Development Group, Inc., 2000  Terms of use are as specified in license.txt#ifndef __EXC_H#define __EXC_H#include "breaker.h"     // breaker#include "typ.h"         // bool#include "xassert.h"     // xassert, for convenience for #includers#include "str.h"         // string#include <iostream.h>    // ostream// forward declarationsclass stringBuilder;// by using this macro, the debugger gets a shot before the stack is unwound#ifdef THROW#undef THROW#endif#define THROW(obj) \  { breaker(); throw (obj); }// this function returns true if we're in the process of unwinding the// stack, and therefore destructors may want to avoid throwing new exceptions;// for now, may return false positives, but won't return false negativesbool unwinding();// inside a catch expression, the unwinding() function needs a tweak; pass// the caught expression, and this returns whether there any *additional*// exceptions currently in flightclass xBase;bool unwinding_other(xBase const &x);// using unwinding() in destructors to avoid abort()#define CAUTIOUS_RELAY           \  catch (xBase &x) {             \    if (!unwinding_other(x)) {   \      throw;   /* re-throw */    \    }                            \  }// intent is to derive all exception objects from thisclass xBase {  string msg;    // the human-readable description of the exceptionpublic:  static bool logExceptions;    // initially true; when true, we write a record of the thrown exception    // to clog  static int creationCount;    // current # of xBases running about; used to support unrolling()public:  xBase(char const *m);    // create exception object with message 'm'  xBase(xBase const &m);   // copy ctor  virtual ~xBase();  char const *why() const    { return (char const*)msg; }  void insert(ostream &os) const;  friend ostream& operator << (ostream &os, xBase const &obj)    { obj.insert(os); return os; }    // print why};// thrown by _xassert_fail, declared in xassert.h// throwing this corresponds to detecting a bug in the programclass x_assert : public xBase {  string condition;          // text of the failed condition  string filename;           // name of the source file  int lineno;                // line numberpublic:  x_assert(char const *cond, char const *fname, int line);  x_assert(x_assert const &obj);  ~x_assert();  char const *cond() const { return (char const *)condition; }  char const *fname() const { return (char const *)filename; }  int line() const { return lineno; }};// throwing this means a formatting error has been detected// in some input data; the program cannot process it, but it// is not a bug in the programclass xFormat : public xBase {  string condition;          // what is wrong with the inputpublic:  xFormat(char const *cond);  xFormat(xFormat const &obj);  ~xFormat();  char const *cond() const { return (char const*)condition; }};// compact way to throw an xFormatvoid xformat(char const *condition);// convenient combination of condition and human-readable message#define checkFormat(cond, message) \  ((cond)? (void)0 : xformat(message))#endif // __EXC_H

⌨️ 快捷键说明

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