All Projects → sindresorhus → ExceptionCatcher

sindresorhus / ExceptionCatcher

Licence: MIT license
Catch Objective-C exceptions in Swift

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to ExceptionCatcher

raise if
one liner `raise Exception if condition` for Python
Stars: ✭ 15 (-84.54%)
Mutual labels:  exceptions, exception-handler
mwe-cpp-exception
Minimum working example of proper C++11 exception handling
Stars: ✭ 20 (-79.38%)
Mutual labels:  exceptions, exception-handler
crash
Proper error handling, exceptions and try/catch for ZSH
Stars: ✭ 51 (-47.42%)
Mutual labels:  exceptions, exception-handler
Bugsnag Go
Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
Stars: ✭ 155 (+59.79%)
Mutual labels:  exceptions
Pyrollbar
Error tracking and logging from Python to Rollbar
Stars: ✭ 169 (+74.23%)
Mutual labels:  exceptions
ANE-Exceptions
Exception tracking Adobe AIR Native Extension for Android and iOS
Stars: ✭ 16 (-83.51%)
Mutual labels:  exception-handler
easybuggy4django
EasyBuggy clone built on Django
Stars: ✭ 44 (-54.64%)
Mutual labels:  exceptions
Ben.demystifier
High performance understanding for stack traces (Make error logs more productive)
Stars: ✭ 2,142 (+2108.25%)
Mutual labels:  exceptions
django-http-exceptions
HTTP exceptions for django
Stars: ✭ 29 (-70.1%)
Mutual labels:  exceptions
Coderr.Client
Core client library for Coderr
Stars: ✭ 23 (-76.29%)
Mutual labels:  exceptions
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-47.42%)
Mutual labels:  exceptions
Object Oriented Programming Using Python
Python is a multi-paradigm programming language. Meaning, it supports different programming approach. One of the popular approach to solve a programming problem is by creating objects. This is known as Object-Oriented Programming (OOP).
Stars: ✭ 183 (+88.66%)
Mutual labels:  exceptions
FPChecker
A dynamic analysis tool to detect floating-point errors in HPC applications.
Stars: ✭ 26 (-73.2%)
Mutual labels:  exceptions
Bugsnag Ruby
Bugsnag error monitoring & reporting software for rails, sinatra, rack and ruby
Stars: ✭ 211 (+117.53%)
Mutual labels:  exceptions
Bugsnag Cocoa
Bugsnag crash reporting for iOS, macOS and tvOS apps
Stars: ✭ 167 (+72.16%)
Mutual labels:  exceptions
rollbar-java
Rollbar for Java and Android
Stars: ✭ 71 (-26.8%)
Mutual labels:  exceptions
Safely
Safely is a Clojure's circuit-breaker library for handling retries in an elegant declarative way.
Stars: ✭ 152 (+56.7%)
Mutual labels:  exceptions
Exceptions4c
🐑 An exception handling framework for C
Stars: ✭ 189 (+94.85%)
Mutual labels:  exceptions
backtrace-unity
First-class error reporting for the Unity game engine.
Stars: ✭ 99 (+2.06%)
Mutual labels:  exception-handler
exceptions-java
Curso Tratamento de Exceções em Java
Stars: ✭ 489 (+404.12%)
Mutual labels:  exceptions

ExceptionCatcher

Catch Objective-C exceptions in Swift

There 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.

The ability to catch exceptions should really be built into Swift. If you agree, duplicate this Feedback Assistant report.

Install

Add the following to Package.swift:

.package(url: "https://github.com/sindresorhus/ExceptionCatcher", from: "2.0.0")

Or add the package in Xcode.

Usage

import Foundation
import ExceptionCatcher

final class Foo: NSObject {}

do {
	let value = try ExceptionCatcher.catch {
		return Foo().value(forKey: "nope")
	}

	print("Value:", value)
} catch {
	print("Error:", error.localizedDescription)
	//=> Error: [valueForUndefinedKey:]: this class is not key value coding-compliant for the key nope.

	debugPrint(error)
	/*
	Error Domain=NSUnknownKeyException Code=0 "[valueForUndefinedKey:]: this class is not key value coding-compliant for the key nope." UserInfo={CallStackSymbols=(
	0   CoreFoundation                      0x00007fff361798ab __exceptionPreprocess + 250
	1   libobjc.A.dylib                     0x00007fff6c3ea805 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff361a230c -[NSException raise] + 9
	3   Foundation                          0x00007fff388f86c4 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 222
	4   Foundation                          0x00007fff3876f8fd -[NSObject(NSKeyValueCoding) valueForKey:] + 317
	5   ExceptionCatcherTests               0x0000000103402ef6 $s21ExceptionCatcherTestsAAC9testCatchyyKFypSgyXEfU1_ + 118

	*/
}

Related

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].