{"id":27361305,"url":"https://github.com/mkropat/betterwin32errors","last_synced_at":"2025-09-14T07:40:03.685Z","repository":{"id":65414206,"uuid":"83244003","full_name":"mkropat/BetterWin32Errors","owner":"mkropat","description":"A better interface to the constants defined in winerror.h","archived":false,"fork":false,"pushed_at":"2022-03-19T00:36:42.000Z","size":12,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-27T13:05:39.280Z","etag":null,"topics":["error","interop","pinvoke","win32api"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkropat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-26T22:04:40.000Z","updated_at":"2023-09-08T17:21:31.000Z","dependencies_parsed_at":"2023-01-23T10:55:09.510Z","dependency_job_id":null,"html_url":"https://github.com/mkropat/BetterWin32Errors","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkropat/BetterWin32Errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkropat%2FBetterWin32Errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkropat%2FBetterWin32Errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkropat%2FBetterWin32Errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkropat%2FBetterWin32Errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkropat","download_url":"https://codeload.github.com/mkropat/BetterWin32Errors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkropat%2FBetterWin32Errors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275076533,"owners_count":25401313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error","interop","pinvoke","win32api"],"created_at":"2025-04-13T01:38:59.997Z","updated_at":"2025-09-14T07:40:03.660Z","avatar_url":"https://github.com/mkropat.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BetterWin32Errors\n\n[![NuGet](https://img.shields.io/nuget/dt/BetterWin32Errors.svg)](https://www.nuget.org/packages/BetterWin32Errors/)\n\n\nA better interface to the constants defined in winerror.h\n\n### Simplified Error Handling\n\nInstead of:\n\n```csharp\nif (!SomeWin32ApiCall(...))\n{\n    throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());\n}\n```\n\nYou can do this:\n\n```csharp\nif (!SomeWin32ApiCall(...))\n{\n    throw new BetterWin32Errors.Win32Exception();\n}\n```\n\n### Access To Error Constants\n\nInstead of re-defining platform constants in your code:\n\n```csharp\nconst int ERROR_FILE_NOT_FOUND = 2;\nconst int ERROR_PATH_NOT_FOUND = 3;\n\nif (!SomeWin32ApiCall(...))\n{\n    var error = Marshal.GetLastWin32Error();\n    if (error == ERROR_FILE_NOT_FOUND)\n    {\n        // ...do something...\n    }\n    else if (error == ERROR_PATH_NOT_FOUND)\n    {\n        // ...do something else...\n    }\n    else\n    {\n      throw new System.ComponentModel.Win32Exception(error);\n    }\n}\n```\n\nYou can do this:\n\n```csharp\nif (!SomeWin32ApiCall(...))\n{\n    var error = Win32Exception.GetLastWin32Error();\n    if (error == Win32Error.ERROR_FILE_NOT_FOUND)\n    {\n        // ...do something...\n    }\n    else if (error == Win32Error.ERROR_PATH_NOT_FOUND)\n    {\n        // ...do something else...\n    }\n    else\n    {\n        throw new Win32Exception(error);\n    }\n}\n```\n\n### Exception Has Both ID and Message\n\n```csharp\ntry\n{\n    // ...some code...\n}\ncatch (BetterWin32Errors.Win32Exception ex)\n\twhen (ex.Error == Win32Error.ERROR_FILE_NOT_FOUND) // use `Error` to get the error ID\n{\n\tConsole.WriteLine(\"Warning: \" + ex.ErrorMessage);\n    // Output: \"Warning: The system cannot find the file specified\"\n}\n```\n\n## Installation\n\n```powershell\nInstall-Package BetterWin32Errors\n```\n\nThe only import you need to know is:\n\n```csharp\nusing BetterWin32Errors;\n```\n\n## Limitations\n\nThere are thousands of error constants defined in [\u0026lt;winerror.h\u0026gt;](https://msdn.microsoft.com/en-us/library/windows/desktop/ms681381.aspx). All error constants included in this library were parsed using a [script](https://github.com/mkropat/BetterWin32Errors/blob/master/BetterWin32Errors/winerror2enum.ps1). As such, __there is no guarantee that the error constants have the correct values in all cases and for all platforms__. Feel free to [submit an issue](https://github.com/mkropat/BetterWin32Errors/issues) if you run into such a problem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkropat%2Fbetterwin32errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkropat%2Fbetterwin32errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkropat%2Fbetterwin32errors/lists"}