Swift Mapping for Local Exceptions

On this page:

Mapped Swift Class

A local Slice exception is mapped to a Swift class with the same name. For example:

Slice
module Ice
{
    local exception InitializationException
    {
        ...
    }
}

is mapped to the Swift class InitializationException:

Swift
open class InitializationException: LocalException {
    // ...
}

Base Class for Local Exceptions in Swift

All mapped Swift classes for local exceptions inherit from class LocalException:

Swift
open class LocalException: Exception, CustomStringConvertible {
    public let file: String
    public let line: Int

    public var description: String {
        return "\(file): \(line): \(ice_id())\(ice_print())"
    }

    public init(file: String = #file, line: Int = #line) {
        // ...
    }

    open class func ice_staticId() -> String {
        return "::Ice::LocalException"
    }

    open func ice_print() -> String {
        return ""
    }
}

Mapping for Local Exception Inheritance in Swift

A local Slice exception can extend another Slice exception, which is mapped to class inheritance in Swift. For example:

Slice
module M
{
    local exception ErrorBase {}
    local exception ResourceError extends ErrorBase {}
}

is mapped to:

Swift
open class ErrorBase: Ice.LocalException {
    // ...
}

open class ResourceError: ErrorBase {
    // ...
}