diff options
author | Murray Cumming <murrayc@src.gnome.org> | 2003-01-15 16:30:15 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@src.gnome.org> | 2003-01-15 16:30:15 +0000 |
commit | b9c14cc56d3db2fefc252c28d63042827351616b (patch) | |
tree | 1791f6be3f12913dd0fb28d2e7ffd237686ae3fc /tests/test_exception_catch.cc | |
parent | a6c78f49e2636a4f5b1fa4c5f120bae5467bcc16 (diff) | |
download | sigc++-b9c14cc56d3db2fefc252c28d63042827351616b.tar.gz |
Added missing files.
Diffstat (limited to 'tests/test_exception_catch.cc')
-rw-r--r-- | tests/test_exception_catch.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_exception_catch.cc b/tests/test_exception_catch.cc new file mode 100644 index 0000000..c6e3b37 --- /dev/null +++ b/tests/test_exception_catch.cc @@ -0,0 +1,46 @@ +// -*- c++ -*- +/* Copyright 2002, The libsigc++ Development Team + * Assigned to public domain. Use as you wish without restriction. + */ + +#include <sigc++/adaptors/exception_catch.h> +#include <iostream> +#include <stdexcept> + +using namespace std; +using namespace sigc::functor; + +struct f +{ + int operator()(int i) + {cout << "f(int "<<i<<")"<<endl; + throw std::range_error("out of range");} +}; +#if 0 +struct g +{ + int operator()() + {cout << "g()"<<endl; + throw std::range_error("out of range");} +}; +#endif + +struct my_catch +{ + int operator()() + { + try { throw; } + catch (std::range_error e) // catch what types we know + { + cerr << "caught "<< e.what() <<endl; + } + return 1; + // all else continues out. + } +}; + +int main() +{ + exception_catch(f(), my_catch())(1); +// exception_catch(g(), my_catch())(); +} |