-
December 13th, 2015, 11:20 AM
#1
Exception Handling in Swift
Hello, we've been having some issues with NSException handling in our app. The crashes are not consistent but usually occur in the client.subscribeTableWithExtendedInfo: method:
*** Terminating app due to uncaught exception 'Lightstreamer server exception', reason: 'Server exception (reason: 'Lightstreamer sync error received')'
*** First throw call stack:
(0x29117f8f 0x37a64c8b 0x9da1bb 0x9ce965 0x9cdf31 0x9cddd7 0x24a784 0xfe850 0x27af173 0x27b9c39 0x27bae19 0x38159db5 0x38159b08)
libc++abi.dylib: terminating with uncaught exception of type LSPushServerException
I've read your forum posts and you mostly say that we should handle the exceptions, which is fine, but you use NSException which is not catchable in Swift. Do you have any suggestions or insights as to how we can handle this optimally?
-
December 14th, 2015, 08:05 AM
#2
Hello,
latest stable branch of the client library, version 1.4.x compatible with serve 6.x, provides alternative methods that include an NSError as the last argument. I.e.
- (LSSubscribedTableKey *) subscribeTableWithExtendedInfo: (LSExtendedTableInfo *)tableInfo delegate: (id <LSTableDelegate>)delegate useCommandLogic: (BOOL)commandLogic error: (NSError * __autoreleasing *)error;
From Swift 2.0 it appears as a throws method. It is included with the latest server distribution.
Note: it is not compatible with server version 5.x and earlier.
Alternatively, we are working on a Unified Client API version of the client library, currently in alpha, that throws no such exceptions but rather delivers them asynchronously via the subscription delegate. It is available on CocoaPods, or you may find direct download links on the blog post introducing the new library.
Note: it is not compatible too with server version 5.x and earlier. Moreover, the APIs change substantially.
Hope this helps. Best regards,
Gianluca
-
December 14th, 2015, 09:53 AM
#3
Thank you for the quick reply, we'll check the newest version.
-
February 3rd, 2016, 10:21 AM
#4
Hi all,
I have issues catching exception in Swift as well with the following code:
public func unsubscibeElement(tableKey tableKey: LSSubscribedTableKey) {
do {
//self.client is an instance of LSClient
try self.client.unsubscribeTable(tableKey, error: ())
}
catch {
print("Error occured")
}
}
It does not catch LSPushClientException "Table not found". This version of the unsubscribe function becomes throwing in Swift but it looks like there is a little interoperability issue.
Thanks for your help.
-
February 4th, 2016, 08:54 AM
#5
Hello,
the LSPushClientException is one of those exceptions related to programming errors that are not wrapped in an NSError. In particular, a "Table not found" is probably due to unsubscribing the same table twice. This is also stated in the method documentation.
Best regards,
Gianluca
-
February 4th, 2016, 10:43 AM
#6
@jpsauvager, as mentioned in a previous post, you might want to check out the new version of the iOS API for Lightstreamer (the Unified Client API). It throws no such exceptions but rather delivers them asynchronously via the subscription delegate. You can find full details here: http://blog.lightstreamer.com/2015/10/new-client-apis-for-ios-and-os-x.html
Similar Threads
-
By Sathyaayyanar in forum Adapter SDKs
Replies: 5
Last Post: June 26th, 2015, 08:49 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
All times are GMT +1. The time now is 05:57 AM.
Bookmarks