Throwing the Result of a Conditional Expression - C++ Statement

C++ examples for Statement:throw

Description

Throwing the Result of a Conditional Expression

Demo Code

#include <iostream>
#include <stdexcept>

int main(int argc, const char *argv[]) {
    try {// ww w  .  ja  va2s  . c  o m
        int i = 6;
        double d = 6.5;

        false ? throw i : throw d;  // double should throw
    } catch (int i) {
        std::cout << "i was thrown" << std::endl;
    } catch (double d) {
        std::cout << "d was thrown" << std::endl;
    }
    return 0;
}

Result


Related Tutorials