
#include<studio.h>
int main()
{
Printf(\\\"Hello world!\\\")
Return 0;
}
In C programming exception handling is not supported natively as it is in other languages that have built-in exception handling mechanisms. However, we can handle exceptional situations or errors using error codes or return values.
The C programming language does not support exception handling nor error handling. It is an additional feature offered by C. In spite of the absence of this feature, there are certain ways to implement error handling in C. Generally, in case of an error, most of the functions either return a null value or -1.
Although C does not provide direct support to error handling (or exception handling), there are ways through which error handling can be done in C. A programmer has to prevent errors at the first place and test return values from the functions.
A lot of C function calls return a -1 or NULL in case of an error, so quick test on these return values are easily done with for instance an ‘if statement’. For example, In Socket Programming, the returned value of the functions like socket(), listen() etc. are checked to see if there is an error or not.
Example: Error handling in Socket Programming
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
perror(“socket failed”);
exit(EXIT_FAILURE);
}
Responding to undesirable or unexpected events that occur while a computer program is running is known as exception handling.
Without this process, exceptions would interfere with a program’s regular functioning and cause it to crash.
Exception handling deals with these events to prevent this from happening.
