[TIMOB-25906] iOS: Native exceptions not thrown when using run-on-main-thread
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-05-04T07:59:05.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.3.0 |
Components | iOS |
Labels | mainthread, try-catch |
Reporter | Michiel van Eerd |
Assignee | Vijay Singh |
Created | 2018-03-27T08:04:53.000+0000 |
Updated | 2018-07-05T18:11:07.000+0000 |
Description
According to the documentation I should get an exception when I try to parse invalid XML with Ti.XML.parseString, but instead the "catch" handler is not called. So either this is a bug or the docs are wrong.
try {
var doc = Ti.XML.parseString("some invalid XML");
} catch (ex) {
// On iOS we never get here
console.log("Exception");
}
*EDIT by [~hknoechel]*: Updating ticket to focus on exceptions on the main thread. The underlaying issue is that we currently do not throw native exceptions (using @throw
) when running on main-thread. While this does not crash the app, it still limits the functionality of developers, so it should be fixed.
Quick question: In the title you mention iOS, in the environment Android. Where is this happening? Tested on iOS and it indeed does not call the exception, but also does not crash, it simply logs it:
[~vijaysingh] Looking in the source, it might be related to the main-thread vs kroll-thread safety. Can you take a look?
Sorry my mistake: It's happening on iOS, I haven't tested it on Android.
I have checked it again and the reason my app crashes is that I did not check the "doc" variable. This was null, so trying to get doc.documentElement causes the app to crash, not the parsing of invalid XML. There is still a bug though or the documentation should be adjusted. A simple solution is to check for the result.
On Kroll thread it is working fine. Problem is with main thread. I'll look in this.
If I see in code in TiBase.m file -
If we are on main thread here, it will not throw exception. Only it will log the error. If I remove the condition it is working fine. Need to dig out more why this condition was required.
PR - https://github.com/appcelerator/titanium_mobile/pull/9966 Test case from TIMOB-5337 -