LogiQuest
Back to Exception Handling
7

What will be the output of the program?

#include <iostream>
using namespace std;
int divide(int a, int b) {
    if (b == 0) throw "zero";
    return a / b;
}
int main() {
    try {
        cout << divide(8, 2) << " ";
        cout << divide(1, 0) << " ";
    } catch (const char *msg) {
        cout << msg;
    }
    cout << endl;
    return 0;
}
Medium

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.