Exception Handling in C
Implement robust error-handling strategies without built-in exception handling.
1
Exception Handling in C
Unlike languages like C++ and Java, C does not have built-in exception handling.
In this lesson, you will learn:
- How to handle errors using return values.
- How to use
setjmpandlongjmpfor exception handling. - How to use
errnofor system error handling.

2
Handling Errors with Return Values
The simplest way to handle errors in C is to use return values.
Example:
int divide(int a, int b) {
if (b == 0) return -1; // Error code
return a / b;
}
The caller checks the return value for errors.
All lessons in this course
- Debugging with GDB
- Common Runtime Errors
- Exception Handling in C