https://code.google.com/p/segvcatch/

This is a crossplatform C++ library designed to convert a hardware exceptions, such as segmentation fault, or floating point errors, into a software language exceptions, which can be handled later with a try/catch construction.

Other words, it's a crossplatform structured exception handling (SEH).

有时候遇到段错误,我们想把这个异常抓住,segvcatch就可以帮助我们做这个事。

下载好segvcatch-0.9.1.zip后解压看里面的doc.h步骤即可,这里我们提取文件单独测试下

下载地址:http://pan.baidu.com/s/16ViuM

1.提取相关文件

[linux]segvcatch简单使用-LMLPHP

提取的文件如上面的全部.cpp和.h文件,Makefile后面一步再写,.so是后面生成的,.sh一个运行脚本

2.编辑Makefile

CXX        =    g++
TARGET = main
SOURCES = main.cpp
LIBS = -L./ -lsegvcatch
CXXFLAGS= -Wall -fexceptions -fnon-call-exceptions
RM = rm -rf $(TARGET):$(SOURCES)
$(CXX) $^ $(LIBS) -o $@ $(CXXFLAGS) .PHONY:clean
clean:
$(RM) main *.so
.PHONY:lib
lib:segvcatch.cpp
$(CXX) $^ -fPIC -shared -o libsegvcatch.so

3.编译测试(OK!)

#make lib

#make

#./main

Exception catched : My SEGV

Exception catched : My FPE

We are living yet!

05-02 17:28