title: What is the correct way to implement error propagation in C?
body: <p>I come from high-level languages with exceptions (C#, in particular), and I usually only catch exceptions that my logic knows how to handle — otherwise, they propagate and program crashes, but at least it provides a clear information about what happened, and where. I want to implement similar behavior in C. I want, in the small body of my <code>main</code>, to get an error code from the functions that I call, to identify what happened, and to print error message to <code>stderr</code> and quit with the same error code as I got.</p>
  
  <ol>
  <li><p>First question — do people do that in C, and is it a good objective, in terms of architecture, at all?</p></li>
  <li><p>Seconds question is about error return codes and errno. What should I use in my code by default? It seems that these two conventions are used interchangeably in C standard library, and it's pretty confusing.</p></li>
  <li><p>Third question is about error codes themselves. In C# and Java, there are standard exception types that cover almost everything you would typically throw, apart from specific comments. Should I use errno error code table for this purpose, or should I create a separate error code table for my application to include all stuff that it specific to it? Or may be every function should maintain it's own specific table of error codes?</p></li>
  <li><p>And finally, additional information about errors: I found that in C#, at least, it's very useful to be able to throw an exception of predefined type with a specific comment that provides additional information. Is something like this used in C error management? How should I implement it?</p></li>
  <li><p>Why do library functions use return codes <strong>and</strong> errno at the same time instead of sticking to one or the other? What's the benefit in using both?</p></li>
  </ol>