example4_exception_handling.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <random>
#include <stdexcept>

int main() {
    try {
        std::random_device rd;
        std::cout << "Successfully created random_device" << std::endl;

        unsigned int random_number = rd();
        std::cout << "Generated random number: " << random_number << std::endl;
    }
    catch (const std::exception& e) {
        std::cerr << "Exception caught: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}
Back to std_random_device