杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
//  HelperFunctions.swift
//  XCGLogger: https://github.com/DaveWoodCom/XCGLogger
//
//  Created by Dave Wood on 2014-06-06.
//  Copyright © 2014 Dave Wood, Cerebral Gardens.
//  Some rights reserved: https://github.com/DaveWoodCom/XCGLogger/blob/main/LICENSE.txt
//
 
import Foundation
import ObjcExceptionBridging
 
/// Extract the type name from the given object
///
/// - parameter someObject: the object for which you need the type name
///
/// - returns: the type name of the object
func extractTypeName(_ someObject: Any) -> String {
    return (someObject is Any.Type) ? "\(someObject)" : "\(type(of: someObject))"
}
 
// MARK: - Swiftier interface to the Objective-C exception handling functions
/// Throw an Objective-C exception with the specified name/message/info
///
/// - parameter name:     The name of the exception to throw
/// - parameter message:  The message to include in the exception (why it occurred)
/// - parameter userInfo: A dictionary with arbitrary info to be passed along with the exception
func _try(_ tryClosure: @escaping () -> (), catch catchClosure: @escaping (_ exception: NSException) -> (), finally finallyClosure: (() -> ())? = nil) {
    _try_objc(tryClosure, catchClosure, finallyClosure ?? {})
}
 
/// Throw an Objective-C exception with the specified name/message/info
///
/// - parameter name:     The name of the exception to throw
/// - parameter message:  The message to include in the exception (why it occurred)
/// - parameter userInfo: A dictionary with arbitrary info to be passed along with the exception
func _throw(name: String, message: String? = nil, userInfo: [AnyHashable: Any]? = nil) {
    _throw_objc(NSException(name: NSExceptionName(rawValue: name), reason: message ?? name, userInfo: userInfo))
}