#include <iostream>
#include <stdexcept>

int divide(int numerator, int denominator) {
    if (denominator == 0) {
        throw std::runtime_error("Division by zero is not allowed.");
    }
    return numerator / denominator;
}

int main() {
    try {
        int result = divide(10, 2); // This should work
        std::cout << "Result: " << result << std::endl;

        result = divide(5, 0); // This will throw an exception
        std::cout << "Result: " << result << std::endl; // This won't be executed
    } catch (const std::exception& e) {
        std::cerr << "An error occurred: " << e.what() << std::endl;
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: