{"id":17129423,"url":"https://github.com/sergiusthebest/exceptxx","last_synced_at":"2025-06-25T01:14:21.933Z","repository":{"id":73478998,"uuid":"86040512","full_name":"SergiusTheBest/exceptxx","owner":"SergiusTheBest","description":"C++ exception handling library","archived":false,"fork":false,"pushed_at":"2024-01-17T14:40:39.000Z","size":43,"stargazers_count":40,"open_issues_count":0,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-25T01:14:18.653Z","etag":null,"topics":["cpp11","cross-platform","error-handling","exception","header-only","try-catch"],"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/SergiusTheBest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-24T07:39:40.000Z","updated_at":"2025-02-13T11:42:08.000Z","dependencies_parsed_at":"2025-04-13T06:42:11.027Z","dependency_job_id":null,"html_url":"https://github.com/SergiusTheBest/exceptxx","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/SergiusTheBest/exceptxx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SergiusTheBest%2Fexceptxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SergiusTheBest%2Fexceptxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SergiusTheBest%2Fexceptxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SergiusTheBest%2Fexceptxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SergiusTheBest","download_url":"https://codeload.github.com/SergiusTheBest/exceptxx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SergiusTheBest%2Fexceptxx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261783463,"owners_count":23208956,"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","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":["cpp11","cross-platform","error-handling","exception","header-only","try-catch"],"created_at":"2024-10-14T19:09:37.595Z","updated_at":"2025-06-25T01:14:21.904Z","avatar_url":"https://github.com/SergiusTheBest.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExceptXX: C++ exception handling library\n[![Build Status](https://travis-ci.org/SergiusTheBest/exceptxx.svg?branch=master)](https://travis-ci.org/SergiusTheBest/exceptxx) [![Build status](https://ci.appveyor.com/api/projects/status/nyo8dtyw9kfq3xhf/branch/master?svg=true)](https://ci.appveyor.com/project/SergiusTheBest/exceptxx/branch/master)\n\n- [Intoduction](#intoduction)\n  - [Features](#features)\n- [Usage](#usage)\n  - [Step 1: Adding includes](#step-1-adding-includes)\n  - [Step 2: Throwing exceptions](#step-2-throwing-exceptions)\n  - [Step 3: Catching exceptions](#step-3-catching-exceptions)\n- [Samples](#samples)\n- [License](#license)\n- [Version history](#version-history)\n\n# Intoduction\nThis library greatly improves and simplifies usage of C++ exceptions. It provides convenient macros for throwing/catching exceptions and checking API errors.\n\nHere is a minimal exceptxx sample:\n```cpp\n#include \u003cexceptxx/Win32Exception.h\u003e\n#include \u003cWindows.h\u003e\n#include \u003ciostream\u003e\n\nusing namespace std;\n\nint main()\n{\n    try\n    {\n        HANDLE h = ::CreateFileW(L\"nonexisting\", 0, 0, nullptr, OPEN_EXISTING, 0, nullptr);\n        THROW_LAST_WIN32_IF(INVALID_HANDLE_VALUE == h) \u003c\u003c \"Ooops, cannot open file 'nonexisting'\";\n    }\n    catch (const exception\u0026 ex)\n    {\n        cerr \u003c\u003c ex.what() \u003c\u003c endl;\n    }\n    \n    return 0;\n}\n```\nand its output:\n```\nText: The system cannot find the file specified (Ooops, cannot open file 'nonexisting')\nError: 2 (WIN32)\nSource: main:12\n```\n\n## Features\n- Header-only\n- Cross-platform: Linux, Windows, macOS (msvc, gcc, clang)\n- Requires C++11\n- Exceptions are convertible to return codes\n- Exceptions carry information about throwing place (function name, line number), error code and description\n- Convenient way to attach an arbitrary user message to exception\n- Ready-made exceptions:\n  - errno\n  - hresult\n  - ntstatus\n  - win32\n  - assert\n  - precondition\n  - cuda\n  - npp\n- Macros for conditional exception throwing\n\n# Usage\nTo start using exceptxx you need to make 3 simple steps.\n\n## Step 1: Adding includes\nAt first your project needs to know about exceptxx. For that you have to:\n\n1. Add `exceptxx/include` to the project include paths\n2. Add `#include \u003cexceptxx/{{desired exception}}.h\u003e` into your cpp/h files (if you have precompiled headers it is a good place to add this include there)\n\n## Step 2: Throwing exceptions\n\nExceptXX exceptions have to be thrown using special macros. There are 2 families of them:\n- `THROW_...(err)`\n- `CHECK_...(err)`\n\n`THROW_...` macros throw an exception with the specified error code while `CHECK_...` macros check the error code to be a failure error code and only then throw an exception.\n\nAlso macros can have a condition: `THROW_..._IF(cond, err)`. In this case an exception is thrown only when the condition is true.\n\nThe following modification of exception throwing macros is designed to be used with API that has a notion of a last error code:\n- `THROW_LAST_...()`\n- `CHECK_LAST_...()`\n\nThese macros can have a condition too:\n- `THROW_LAST_..._IF(cond)`\n- `CHECK_LAST_..._IF(cond)`\n\nExamples:\n```cpp\nTHROW_HRESULT(E_ACCESS);\nCHECK_ERRNO(res);\nTHROW_LAST_WIN32_IF(!res);\n```\n\n## Step 3: Catching exceptions\nThere are helper macros for try-catch blocks. They store caught exception in a variable that can be analyzed later. Also they catch and wrap `std::exception`.\n\n```cpp\nint foo()\n{\n    XX_TRY(ex) // declare exception variable\n    {\n        CHECK_ERRNO(EACCES);\n    }\n    XX_CATCH(ex);\n\n    if (ex)\n    {\n        cerr \u003c\u003c ex-\u003ewhat() \u003c\u003c endl;\n    }\n    \n    return ex;\n}\n```\n\n# Samples\nThere are a number of samples that demonstrate various aspects of using exceptxx. They can be found in the [samples](samples) folder:\n- [Assert](samples/Assert)\n- [Errno](samples/Errno)\n- [Hresult](samples/Hresult)\n- [Ntstatus](samples/Ntstatus)\n- [Precond](samples/Precond)\n- [Std](samples/Std)\n- [TryCatch](samples/TryCatch)\n- [Win32](samples/Win32)\n  \n# License\nExceptXX is licensed under the [MIT license](https://choosealicense.com/licenses/mit). You can freely use it in your commercial or opensource software.\n\n# Version history\n\n## Version 1.0.0 (08 Oct 2019)\n- Initial public release","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergiusthebest%2Fexceptxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergiusthebest%2Fexceptxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergiusthebest%2Fexceptxx/lists"}