Coder Social home page Coder Social logo

exceptioncatcher's Introduction

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

exceptioncatcher's People

Contributors

sindresorhus avatar tomlokhorst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

exceptioncatcher's Issues

SPM Warning with deployment target iOS 13+

Our current deployment target: iOS 13.0
And we get the following error for the added Swift package:

The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99.

A version bump to v9 in the Package.swift could solve the problem. If you mind I can open a PR for that.

complied xcframwork throws "missing required module 'internal'"

I have my own framework and that is now dependent on ExceptionCatcher.

After compiling my framework to xcframework and then using into test app, before distribution is throwing error at build time with the message `missing required module "internal"'

Do you know how can I get this internal module of exceptionCatcher into the xcframework?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.