This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Showing posts with label Write a program containing a possible exception. Use a try block to throw it and a catch block to handle it properly.. Show all posts
Showing posts with label Write a program containing a possible exception. Use a try block to throw it and a catch block to handle it properly.. Show all posts

Friday, March 17, 2023

Write a program containing a possible exception. Use a try block to throw it and a catch block to handle it properly.

March 17, 2023 0
 Here is an example program that demonstrates the use of try and catch block to handle an exception:#include <iostream>#include <string>using namespace std;void divide(int a, int b) {    if (b == 0) {        throw "Divide by zero exception";    }    cout << "a/b = " << a/b << endl;}int main() {    int a, b;    cout << "Enter two numbers: "; ...

Slider Widget