In another lang. there is try catch so I can write the exception to log file , and fix that later.
How can I do it in c? so if I have an error I can see it , write it to log , and my process will not droped
thanks
Printable View
In another lang. there is try catch so I can write the exception to log file , and fix that later.
How can I do it in c? so if I have an error I can see it , write it to log , and my process will not droped
thanks
C does not have a native exception feature. As such, you have to take care to check all relevant error status return values, error status output parameters, and/or call functions that tell you the error status of whatever you're working with, and then log the errors, if any, returning an error code in that function.
On Windows under Visual Studio you can have structured exception handling for C.
Be aware that your code won't work on other compilers.
Structured Exception Handling (C/C++) | Microsoft Docs
I strongly recommend sticking to Standard C and stay away from "Windows extensions" and any other O/S and/or compiler extensions! Simple enough to write your own error handling function that can write out messages to a log file, that will work on any O/S, compiler combination.
The OP has not stated the O/S or compiler being used.
True, but that's the C way.Quote:
That not so simple to handle each error that can happend,
The C grammar is given in that article, and the main function in the example doesn't use anything C++ specific in itself. Anyway, as you can see SEH isn't a general exception feature such that you can easily throw your own exceptions; it provides a structured way to handle exceptions arising from "certain exceptional code situations, such as hardware faults, gracefully".