]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/example/example13.cpp
4 #include <boost/safe_numerics/safe_integer.hpp>
6 int main(int, const char *[]){
7 // problem: cannot recover from arithmetic errors
8 std::cout
<< "example 7: ";
9 std::cout
<< "cannot recover from arithmetic errors" << std::endl
;
10 std::cout
<< "Not using safe numerics" << std::endl
;
15 // can't do this as it will crash the program with no
16 // opportunity for recovery - comment out for example
17 // std::cout << x / y;
18 std::cout
<< "error cannot be handled at runtime!" << std::endl
;
20 catch(const std::exception
&){
21 std::cout
<< "error handled at runtime!" << std::endl
;
23 // solution: replace int with safe<int>
24 std::cout
<< "Using safe numerics" << std::endl
;
26 using namespace boost::safe_numerics
;
27 const safe
<int> x
= 1;
28 const safe
<int> y
= 0;
30 std::cout
<< "error NOT detected!" << std::endl
;
32 catch(const std::exception
& e
){
33 std::cout
<< "error handled at runtime!" << e
.what() << std::endl
;