Skip to content

consider ObjC exception catcher in each Task? #1077

@tomholub

Description

@tomholub

It would be good to use this: https://stackoverflow.com/questions/32758811/catching-nsexception-in-swift everywhere.

Having this everywhere will make code looks verbose. We could use it in potential dangerous places but wrapping each objc function/method is too much.

That would be verbose, yes. The issue is that almost anything can potentially throw ObjC exception. MailCore - ObjC. Gmail API - ObjC. Texture - ObjC.

Do we necessarily have to catch it exactly on the first boundary from ObjC to Swift? Or could it be later? Best would be if we only had to do it once per Task - then it's not too verbose.

fun handle() {
  Task {
    do {
      try ObjC.catch {
        try await thisCanThrowSwift()
        try await thisCallsMethodThatCallsMethodThatCanThrowObjc()
        thisCanTrhowObjC()
        someOtherCode()
      }
    } catch {
      handle(error)
    }
  }
}

Originally posted by @tomholub in #1076 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions