{"id":21028211,"url":"https://github.com/exyi/recordexception","last_synced_at":"2026-04-28T10:05:02.430Z","repository":{"id":65413725,"uuid":"401459454","full_name":"exyi/RecordException","owner":"exyi","description":"Define custom exceptions as C# records. ","archived":false,"fork":false,"pushed_at":"2021-11-07T14:42:35.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-23T11:25:31.757Z","etag":null,"topics":[],"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/exyi.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}},"created_at":"2021-08-30T19:16:43.000Z","updated_at":"2023-08-19T17:56:56.000Z","dependencies_parsed_at":"2023-01-22T09:35:11.333Z","dependency_job_id":null,"html_url":"https://github.com/exyi/RecordException","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exyi%2FRecordException","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exyi%2FRecordException/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exyi%2FRecordException/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exyi%2FRecordException/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exyi","download_url":"https://codeload.github.com/exyi/RecordException/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243467024,"owners_count":20295309,"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":[],"created_at":"2024-11-19T11:54:19.696Z","updated_at":"2025-12-29T10:37:55.984Z","avatar_url":"https://github.com/exyi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# `record`s inheriting from `Exception`\n\nInstall [from NuGet](https://www.nuget.org/packages/RecordException): `dotnet add package RecordException`\n\nThen define your exceptions like this:\n\n```csharp\nusing RecordExceptions;\n\npublic record MissingIdException(int id): RecordException;\n\n```\n\nThe exception message will automatically be `MissingIdException: id = {id}`.\nProbably fine for debugging, but if you want to customize that, you can:\n\n```csharp\npublic record MissingIdException(int id): RecordException\n{\n    public override string Message =\u003e $\"Id {id} is missing\";\n}\n```\n\nThe message may also be specified in the construtor:\n\n```csharp\npublic record OperationCancelledException: RecordException(\"User has cancelled the operation.\")\n```\n\nYou can also wrap exception into InnerException, it might be useful for adding relevant information:\n\n```csharp\npublic record SomethingBad(Exception InnerException): RecordException(\"Something really bad has happened\", InnerException);\n```\n\nNotes:\n\n* If you are using some parameters in your message, prefer to override the Message property if you want the `x with { Prop = newValue }` syntax to work.\n* Even when you provide your own message, all properties will be shown bellow the stacktrace. If you don't like this, `public override string ToString() =\u003e base.ToString();`.\n* Don't be too surprised if this stops working with the next C# version 😅. Yes, records are not supposed to inherit from System.Exception. But they forgot to check base type of a base type ;)\n\n\n\nLicense is MIT, so you can use it however you want to. If you need a record inheriting from another class, feel free to fork this repo.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexyi%2Frecordexception","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexyi%2Frecordexception","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexyi%2Frecordexception/lists"}