![]() |
VOOZH | about |
Exceptions are runtime anomalies or abnormal conditions that a program encounters during its execution. C doesn’t provide any specialized functionality for this purpose like other programming languages such as C++ or Java. However, In C, goto keyword is often used for the same purpose. The goto statement can be used to jump from anywhere to anywhere within a function.
Syntax:
The goto statement in C provides a way to jump to a labeled part of the code. While generally discouraged in modern programming due to readability and maintainability concerns, goto can be a clean solution for error handling in specific scenarios like:
The following examples demonstrate the use of goto for exception handling in C:
Exception: Division by zero is not allowed!
Error opening file
Though it works fine, goto have some limitations as compared to the specialized exception handling structures.