`
viMory
  • 浏览: 58133 次
  • 性别: Icon_minigender_1
  • 来自: 土卫六
最近访客 更多访客>>
社区版块
存档分类
最新评论

C++异常处理的一个通用的xcept头文件

    博客分类:
  • 类C
阅读更多
#ifndef Xcept_
#define Xcept_

#include <new.h>

// bad initializers
class BadInitializers {
    public:
       BadInitializers() {}
};

// insufficient memory
class NoMem {
    public:
       NoMem() {}
};

// change new to throw NoMem instead of standard behavior
// Visual C++ requires following form of my_new_handler
int my_new_handler(size_t x)
{
    throw NoMem();
    // even though the following statement is unreachable,
    // visual C++ will not compile successfully without it
    return 0;
};

_PNH Old_Handler_ = _set_new_handler(my_new_handler);

// improper array, find, insert, or delete index
// or deletion from empty structure
class OutOfBounds {
    public:
       OutOfBounds() {}
};

// use when operands should have matching size
class SizeMismatch {
    public:
       SizeMismatch() {}
};

// use when zero was expected
class MustBeZero {
    public:
       MustBeZero() {}
};

// use when zero was expected
class BadInput {
    public:
       BadInput() {}
};

#endif

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics