Error handling
What is Error handling?
Different methods of Error handling
// err_p1_1.c
#include <stdio.h>
int solution(int a,int b)
{
if (b > 0) {
return a / b;
}
return -1;
}
int main() {
printf("%d\n",solution(102,0));
printf("%d\n",solution(955,5));
printf("%d\n",solution(1650,2));
return 0;
}// err_p1_2.cpp
#include <iostream>
using namespace std;
int myFunction(int a,int b) {
if (b == 0) {
return -1;
}
return a/b;
}
int main() {
cout << myFunction(102,0) << endl;
cout << myFunction(955,5) << endl;
cout << myFunction(1650,2) << endl;
return 0;
} Global Variable errno

perror() and strerror()
Exit Status
Last updated
Was this helpful?