异常

最后更新于:2022-04-02 02:33:35

[TOC] ## 示例 ### hello word
main.cpp ``` #include Php::Value myDiv(Php::Parameters ¶ms) { if (params[1] == 0) throw Php::Exception("Division by zero"); return params[0] / params[1]; } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension extension("my_extension", "1.0"); extension.add("myDiv", { Php::ByVal("a", Php::Type::Numeric, true), Php::ByVal("b", Php::Type::Numeric, true) }); return extension; } } ```

main.php ``` getMessage()); // Division by zer } ```

### 捕获C ++中的异常
main.cpp ``` #include Php::Value callMe(Php::Parameters ¶ms) { try { return params[0](); } catch (Php::Exception &exception) { return "Exception caught!\n"; } } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension extension("my_extension", "1.0"); extension.add("callMe", { Php::ByVal("callback", Php::Type::Callable, true) }); return extension; } } ```

main.php ```
';