{"id":13467207,"url":"https://github.com/sindresorhus/ExceptionCatcher","last_synced_at":"2025-03-26T01:30:29.928Z","repository":{"id":63920509,"uuid":"231768028","full_name":"sindresorhus/ExceptionCatcher","owner":"sindresorhus","description":"Catch Objective-C exceptions in Swift","archived":false,"fork":false,"pushed_at":"2025-02-27T14:43:35.000Z","size":16,"stargazers_count":154,"open_issues_count":0,"forks_count":19,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-20T09:21:27.850Z","etag":null,"topics":["exception-handler","exceptions","objective-c","swift-package"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/sindresorhus.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},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2020-01-04T13:27:32.000Z","updated_at":"2025-03-16T00:24:39.000Z","dependencies_parsed_at":"2022-11-29T10:45:32.122Z","dependency_job_id":"5cc9d727-5401-420c-bb34-dee421bd4b65","html_url":"https://github.com/sindresorhus/ExceptionCatcher","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"81cf83b117ec368e2ebb7fbcd9f7a3deb115ab07"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FExceptionCatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FExceptionCatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FExceptionCatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FExceptionCatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/ExceptionCatcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244787013,"owners_count":20510039,"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":["exception-handler","exceptions","objective-c","swift-package"],"created_at":"2024-07-31T15:00:54.090Z","updated_at":"2025-03-26T01:30:29.918Z","avatar_url":"https://github.com/sindresorhus.png","language":"Swift","readme":"# ExceptionCatcher\n\n\u003e Catch [Objective-C exceptions](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html) in Swift\n\nThere are many Cocoa APIs that can throw exceptions that cannot be caught in Swift (`NSKeyedUnarchiver`, `NSTask`,  `NSObject#value(forKey:)`, etc). This package wraps an Objective-C exception handler to make it possible to catch such exceptions.\n\n*The ability to catch exceptions should really be built into Swift. If you agree, duplicate [this](https://github.com/feedback-assistant/reports/issues/74) Feedback Assistant report.*\n\n## Install\n\nAdd the following to `Package.swift`:\n\n```swift\n.package(url: \"https://github.com/sindresorhus/ExceptionCatcher\", from: \"2.0.0\")\n```\n\n[Or add the package in Xcode.](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app)\n\n## Usage\n\n```swift\nimport Foundation\nimport ExceptionCatcher\n\nfinal class Foo: NSObject {}\n\ndo {\n\tlet value = try ExceptionCatcher.catch {\n\t\treturn Foo().value(forKey: \"nope\")\n\t}\n\n\tprint(\"Value:\", value)\n} catch {\n\tprint(\"Error:\", error.localizedDescription)\n\t//=\u003e Error: [valueForUndefinedKey:]: this class is not key value coding-compliant for the key nope.\n\n\tdebugPrint(error)\n\t/*\n\tError Domain=NSUnknownKeyException Code=0 \"[valueForUndefinedKey:]: this class is not key value coding-compliant for the key nope.\" UserInfo={CallStackSymbols=(\n\t0   CoreFoundation                      0x00007fff361798ab __exceptionPreprocess + 250\n\t1   libobjc.A.dylib                     0x00007fff6c3ea805 objc_exception_throw + 48\n\t2   CoreFoundation                      0x00007fff361a230c -[NSException raise] + 9\n\t3   Foundation                          0x00007fff388f86c4 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 222\n\t4   Foundation                          0x00007fff3876f8fd -[NSObject(NSKeyValueCoding) valueForKey:] + 317\n\t5   ExceptionCatcherTests               0x0000000103402ef6 $s21ExceptionCatcherTestsAAC9testCatchyyKFypSgyXEfU1_ + 118\n\t…\n\t*/\n}\n```\n\n## Related\n\n- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults\n- [LaunchAtLogin](https://github.com/sindresorhus/LaunchAtLogin) - Add “ Launch at Login” functionality to your macOS app\n- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift+archived%3Afalse\u0026type=repositories)\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Libs","Utility [🔝](#readme)"],"sub_categories":["Utility"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2FExceptionCatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2FExceptionCatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2FExceptionCatcher/lists"}