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

Provide examples of using WindowsError and SystemError in the docs #54

Closed
vitaut opened this issue Jul 9, 2014 · 6 comments
Closed

Comments

@vitaut
Copy link
Contributor

vitaut commented Jul 9, 2014

Provide 2-3 examples of real Windows error codes in the example so its usage makes sense and mention what happens if you enter a code that is not an official error code.

@patlecat
Copy link

patlecat commented Jul 9, 2014

Okay as discussed, here my example code that will let the user run through the Windows error codes by using the C++11 random generators - because rand() must not be used anymore!
Here's the list btw: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

   #include <chrono>
   #include <random>

   unsigned long ulError = GetLastError(); // Get the error in this way

   // Setup the random number generator
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    std::default_random_engine generator(seed);
    std::uniform_int_distribution<unsigned short> distribution (0, 15999); // Range of the Windows Error Codes
    unsigned short rand_error = distribution (generator);

    fmt::WindowsError gimmError (rand_error, " TestError: ");
    cerr << "\n***ERROR (" << rand_error << ")" << gimmError.what();

Output if you enter a number that is not a Windows error code: ***ERROR (6449) TestError: error code = 6449

@vitaut
Copy link
Contributor Author

vitaut commented Jul 9, 2014

Thanks!

@vitaut
Copy link
Contributor Author

vitaut commented Feb 6, 2015

Added examples, but still need to clarify what happens if you pass an invalid error code.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 7, 2015

Fixed in 326ade7.

@vitaut vitaut closed this as completed Feb 7, 2015
@vitaut
Copy link
Contributor Author

vitaut commented Feb 7, 2015

Took me only 7 months to close this =)

@patlecat
Copy link

patlecat commented Feb 9, 2015

Cool 👍

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

No branches or pull requests

2 participants