Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement std::system_error #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EvanBalster
Copy link

@EvanBalster EvanBalster commented Jul 9, 2021

This patch adds functionality to nng::exception, making it inherit from and implement std::system_error, the standard interface for exceptions based on a numeric code which can be translated into a string name.

This allows:

  • Using NNG exceptions in std::error_code and std::error_condition.
  • Type erasure with other systems of error codes.
  • Translating NNG error codes to the POSIX error codes defined in C++11.

No existing functionality is changed or removed.


The most complicated detail of this patch is the translation to POSIX error codes. Although the standard does not mandate the use of the generic category in default_error_condition, it allows for greater practical similarity with other libraries and can be achieved with only minor wrinkles.

Mappings are implemented as described in #25 where I proposed this functionality. Notably, I'm not sure whether I'm handling NNG_ESYSERR-flagged codes correctly in default_error_condition.

Here's the result of a diagnostic test mapping error codes 0-31, 1000 (EINTERNAL) and ESYSERR|0xC0000005 to their generic equivalents. This was compiled on MSVC:

nng     0       Hunky dory
generic 0       unknown error
nng     1       Interrupted
generic 4       interrupted
nng     2       Out of memory
generic 12      not enough memory
nng     3       Invalid argument
generic 22      invalid argument
nng     4       Resource busy
generic 16      device or resource busy
nng     5       Timed out
generic 138     timed out
nng     6       Connection refused
generic 107     connection refused
nng     7       Object closed
generic 9       bad file descriptor
nng     8       Try again
generic 11      resource unavailable try again
nng     9       Not supported
generic 129     not supported
nng     10      Address in use
generic 100     address in use
nng     11      Incorrect state
generic 25      inappropriate io control operation
nng     12      Entry not found
generic 2       no such file or directory
nng     13      Protocol error
generic 134     protocol error
nng     14      Destination unreachable
generic 110     host unreachable
nng     15      Address invalid
generic 101     address not available
nng     16      Permission denied
generic 1       operation not permitted
nng     17      Message too large
generic 115     message size
nng     18      Connection aborted
generic 106     connection aborted
nng     19      Connection reset
generic 108     connection reset
nng     20      Operation canceled
generic 105     operation canceled
nng     21      Out of files
generic 24      too many files open
nng     22      Out of space
generic 28      no space on device
nng     23      Resource already exists
generic 17      file exists
nng     24      Read only resource
generic 13      permission denied
nng     25      Write only resource
generic 13      permission denied
nng     26      Cryptographic error
generic 13      permission denied
nng     27      Peer could not be authenticated
generic 13      permission denied
nng     28      Option requires argument
generic 22      invalid argument
nng     29      Ambiguous option
generic 22      invalid argument
nng     30      Incorrect type
generic 22      invalid argument
nng     31      Connection shutdown
generic 106     connection aborted
nng     1000    Internal error detected
nng     1000    Internal error detected
nng     -805306363      Unknown error
system  -1073741819     unknown error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant