void divide(int a, int b){ if(b == 0){ throw ErrorResult("Division by zero error"); } cout << a/b; }
try { int result = divide(10, 0); cout << result; } catch (ErrorResult& e) { cout << e.what(); }In this example, we are calling the `divide` function with the parameters `10` and `0`. Since `b` is zero, it will throw an exception. The `try-catch` block in the main function is used to catch the exception and display the message "Division by zero error". This code can also be found in the standard C++ library.