Bifalgorithm post · Computer science one · Error Handling By Design

How can error handling use error codes beyond the three mentioned examples?

How can error handling use error codes beyond the three mentioned examples? (Computer science one · Error Handling By Design) — "Error Handling can be used bey…

Ideas in this flowchart

  • Error handling can use additional mechanisms beyond the three previously mentioned.
  • Standard error codes provide examples of specific error conditions.
  • ENOENT means “No such file or directory.”
  • EACCES means “Permission denied.”
  • A program can communicate errors by setting the errno variable.
  • Using standard or POSIX error codes may create compatibility issues.
  • A more appropriate approach is to communicate errors through a function’s return value.
  • Functions can always return an int value representing an error status.
  • A return value of 0 indicates that no error occurred.
  • A non-zero return value indicates different types of errors.
  • Values that must also be returned should be provided through pass-by-reference variables.
Feed/

How can error handling use error codes beyond the three mentioned examples?

No cover

Channel

Computer science one

1 page

"Error Handling can be used beyond the three mentioned above. For example, the ENOENT error code corresponds to “No such file or directory” and EACCES corresponds to a “Permission denied” error. In our own code we could communicate errors to calling functions by setting the errno variable, however, we may run into compatibility issues with the standard error codes or POSIX error codes. Instead, it may be more appropriate to do error handling by utilizing the return value of a function to communicate an error code. We could design our functions to always return an int value to indicate an error: 0 for no error and some non-zero value to indicate various different types of errors. Of course, as a consequence any value that needs to be “returned” to the calling function would need to be done so via a pass by reference variable."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.