void thrower(SpaceWaster *current) {
    if (current->checkLevel()) throw std::logic_error("some error message goes here\n");
    SpaceWaster next(current->level - 1, current);
    // typical exception-using code doesn't need error return values
    thrower(&next);
    return;
}
示例#2
0
void TestUncaught(void) {
    TInt x = 0;
#ifdef __SUPPORT_CPP_EXCEPTIONS__
    try {
        UncaughtTester aTester(x);
        test.Printf(_L("Check throw case\n"));
        thrower(5);
        test(x == 5);
    }
    catch(MyFirstException& /*e*/)
    {
#if defined(__MSVCDOTNET__) || (defined(__CW32__) && (__MWERKS__ > 0x3200)) || defined(__EABI__)
        test.Printf(_L("~Check x == 2\n"));
        test(x == 2);
#else
        test.Printf(_L("Checking x == 1, as std::uncaught_exception() broken\n"));
        test(x == 1);
#endif
    }
    try
#endif //__SUPPORT_CPP_EXCEPTIONS__
    {
        UncaughtTester aTester(x);
        test.Printf(_L("Check no throw case\n"));
    }
#ifdef __SUPPORT_CPP_EXCEPTIONS__
    catch(MyFirstException& /*e*/)
    {
        test.Printf(_L("Whoops!!!\n"));
    }
#endif //__SUPPORT_CPP_EXCEPTIONS__
    test(x==1);
}
示例#3
0
void
catcher (int signal)
{
  /* Find the next level.  */
  switch (level)
    {
    case MAIN:
      thrower (OUTER, SIGALRM, ITIMER_REAL, SA_ONSTACK);
      break;
    case OUTER:
      thrower (INNER, SIGVTALRM, ITIMER_VIRTUAL, SA_ONSTACK);
      break;
    case INNER:
      level = LEAF;
      return;
    }
}
示例#4
0
int catcher(int x) {
#ifdef __SUPPORT_CPP_EXCEPTIONS__
    try {
#endif //__SUPPORT_CPP_EXCEPTIONS__
        return thrower(x);
#ifdef __SUPPORT_CPP_EXCEPTIONS__
    }
    catch(MyFirstException& e)
    {
        return e.iVal;
    }
#endif //__SUPPORT_CPP_EXCEPTIONS__
}
示例#5
0
void
throw_fwd( void (*thrower)(int) )
    {
    try
        {
        thrower(42);
        }
    catch(
    boost::exception & x )
        {
        x << test_data(42);
        throw;
        }
    }
示例#6
0
文件: error.c 项目: abw/hemp
void test_error_jump() {
    int exception;
    
    if((exception = setjmp(state)) == 0) {              // try
        thrower(HEMP_ERROR_MEMORY, "hello world");
        fail("returned from thrower (this should not happen)\n");
    }
    else {
        switch (exception) {             
            case HEMP_ERROR_MEMORY:
                pass("caught HEMP_ERROR_MEMORY");
                break;
            case HEMP_ERROR_MISSING:
                fail("caught HEMP_ERROR_MISSING");
                break;
            default:
                fail("caught unknown exception: %d", exception);
        }
    }
}
int main() {
    const int repeats = 10001;
    int returns = 0;
    SpaceWaster first(10000, 0);

    for (int i = 0; i < repeats; ++i) {
        #ifdef THROW
            try {
                thrower(&first);
            } catch (std::exception &e) {
                ++returns;
            }
        #else
            returner(&first);
            ++returns;
        #endif
    }
    #ifdef THROW
        std::cout << returns << " exceptions\n";
    #else
        std::cout << returns << " returns\n";
    #endif
}
示例#8
0
main ()
{
  signal (SIGSEGV, catcher);
  thrower ();
}
示例#9
0
inline void notFatal() {thrower();}
示例#10
0
inline void fatal() noexcept {thrower();}