Error Return Value
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the return 0 and return 1 in c programming company Business Learn more about hiring developers or posting ads with us Stack Overflow c error function Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
C Error Handling Best Practices
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Should I return 0 or 1 for successful function? [duplicate] up vote 19 down vote favorite 2 Possible Duplicate:
C Error Codes
Error handling in C code What return value should you use for a failed function call in C? I always use 0, but its not really readable in if, while, etc. Should i return 1? Why main function return 0 for success? c boolean share|improve this question edited Mar 3 '12 at 19:58 David 12.5k32979 asked Mar 3 '12 at 19:55 ziq 4281311 marked as duplicate by Oliver Charlesworth, juergen d, Andrew Marshall, c print to stderr Bart, hvd Mar 3 '12 at 20:01 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 The linked question was closed. –bernie Mar 3 '12 at 19:58 @AdamBernier: As a duplicate. It had some highly relevant answers. –Oliver Charlesworth Mar 3 '12 at 19:59 @Oli: it doesn't seem appropriate that the other question was closed as a duplicate (maybe I'm just not seeing it). Nevertheless I agree with closing that one and this one: The questions do seem too open-ended for this particular website. –bernie Mar 3 '12 at 20:02 This answer depends on whether you want to return error codes, as opposed to true or false. Usually when having multiple return error codes, 0 is success and other values represent errors. I suppose people use 0 as success and nonzero for failure to remain consistent. –Marlon Mar 3 '12 at 20:16 add a comment| 3 Answers 3 active oldest votes up vote 17 down vote accepted It's defined by the C standard as 0 for success (credits go to hvd). But For greater portability, you can use the macros EXIT_SUCCESS and EXIT_FAILURE for the conventional status value for success and failure, respective
Studio 2015 products Visual Studio Team Services Visual Studio Code Visual Studio Dev Essentials Office Office Word/Excel/PowerPoint Microsoft Graph Outlook OneDrive/Sharepoint Skype Services Store Cortana Bing Application Insights Languages
C Errno
& platforms Xamarin ASP.NET C++ TypeScript .NET - VB, C#, F# Server Windows perror c Server SQL Server BizTalk Server SharePoint Dynamics Programs & communities Students Startups Forums MSDN Subscriber downloads Sign in Search c++ error handling Microsoft Search Windows Dev Center Windows Dev Center Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise Windows Store opportunities Docs http://stackoverflow.com/questions/9549342/should-i-return-0-or-1-for-successful-function Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise https://msdn.microsoft.com/en-us/library/windows/desktop/aa369778(v=vs.85).aspx Windows Store opportunities Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Windows Installer About Windows Installer Windows Installer Logging Windows Installer Logging Logging of Action Return Values Logging of Action Return Values Logging of Action Return Values Normal Logging Event Logging Logging of Action Return Values Preventing Confidential Information from Being Written into the Log File TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Logging of Action Return Values The Installer writes the following values into the log when an action returns these error codes. For the entire list of error codes returned by the Windows Installer function calls MsiExec.exe, and InstMsi.exe, see Error Codes. Error CodeValues returned by function calls MsiExec.exe, and InstMsi.exeValues that appear in the Log.Description ERROR_FUNCTION_NOT_CALLED16260A function could not be executed. ERROR_SUCCESS01An action completed su
C - Basic Syntax C - Data Types C - Variables C - Constants C - Storage Classes C - Operators C - Decision Making C - Loops C - Functions C - Scope Rules C - Arrays C - https://www.tutorialspoint.com/cprogramming/c_error_handling.htm Pointers C - Strings C - Structures C - Unions C - Bit Fields C - Typedef C - Input & Output C - File I/O C - Preprocessors C - Header Files C - Type Casting C - http://tldp.org/LDP/abs/html/exitcodes.html Error Handling C - Recursion C - Variable Arguments C - Memory Management C - Command Line Arguments C Programming Resources C - Questions & Answers C - Quick Guide C - Useful Resources C - Discussion Selected c error Reading Developer's Best Practices Questions and Answers Effective Resume Writing HR Interview Questions Computer Glossary Who is Who C - Error Handling Advertisements Previous Page Next Page As such, C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. Most of the C or even Unix function calls return -1 or NULL in case of any error error return value and set an error code errno. It is set as a global variable and indicates an error occurred during any function call. You can find various error codes defined in
>ExampleComments1Catchall for general errorslet "var1 = 1/0"Miscellaneous errors, such as "divide by zero" and other impermissible operations2Misuse of shell builtins (according to Bash documentation)empty_function() {}Missing keyword or command, or permission problem (and diff return code on a failed binary file comparison).126Command invoked cannot execute/dev/nullPermission problem or command is not an executable127"command not found"illegal_commandPossible problem with $PATH or a typo128Invalid argument to exitexit 3.14159exit takes only integer args in the range 0 - 255 (see first footnote)128+nFatal error signal "n"kill -9 $PPID of script$? returns 137 (128 + 9)130Script terminated by Control-CCtl-CControl-C is fatal error signal 2, (130 = 128 + 2, see above)255*Exit status out of rangeexit -1exit takes only integer args in the range 0 - 255