Example #1
0
int main ()
{
    // swap-out the terminate handler
    void (*default_handler)() = std::get_terminate(); 
    std::set_terminate(my_terminate);

#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
    try {
#endif
        Derived &d = test_bad_cast(gB);
        assert(false);
        ((void)d);
#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS
    } catch (std::bad_cast) {
        // success
        return 0;
    } catch (...) {
        assert(false);
    }
#endif

    // failure, restore the default terminate handler and fire
    std::set_terminate(default_handler);
    std::terminate();
}
Example #2
0
int main()
{
  printf ("Results of any_test:\n");
  
  try
  {  
    printf                 ("default construction\n");
    test_default_ctor      ();
    printf                 ("single argument construction\n");
    test_converting_ctor   ();
    printf                 ("copy construction\n");
    test_copy_ctor         ();
    printf                 ("copy assignment operator\n");
    test_copy_assign       ();
    printf                 ("converting assignment operator\n");
    test_converting_assign ();
    printf                 ("failed custom keyword cast\n");
    test_bad_cast          ();
    printf                 ("swap member function\n");
    test_swap              ();
    printf                 ("copying operations on a null\n");
    test_null_copying      ();
  }
  catch (std::exception& exception)
  {
    printf ("fail with exception: %s\n", exception.what ());
  }

  return 0;
}