summaryrefslogtreecommitdiff
path: root/include/fatalerror.h
blob: a5fd25cbd275e1ec51b9a8b3cd94c11b4da6286a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 *  FatalError.h
 *
 *
 *  Normally, fatal errors are reported with a call to zend_error().
 *
 *  However, this will trigger a longjmp(), which will cause objects
 *  constructed in the extension not to be destructed. We use therefore
 *  this FatalError class, which is a normal exception that _does_
 *  cause objects to be destructed.
 *
 *  When it is caught, right before control is handed back to the Zend
 *  engine, it will turn the exception into a zend_error() call and
 *  thus a longjmp.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2014 Copernica BV
 */

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Class definition
 */
class PHPCPP_EXPORT FatalError : public Exception
{
public:
    /**
     *  Constructor
     *  @param  message
     */
    FatalError(const std::string &message) : Exception(message) {}

    /**
     *  Destructor
     */
    virtual ~FatalError() throw()
    {
    }

    /**
     *  Is this a native exception (one that was thrown from C++ code)
     *  @return bool
     */
    virtual bool native() const
    {
        // although it is native, we return 0 because it should not persist
        // as exception, but it should live on as zend_error() in stead
        return false;
    }

    /**
     *  Report this error as a fatal error
     *  @return bool
     */
    virtual bool report() const override;
};

/**
 *  End of namespace
 */
}