Add support to FabricUIManger to handle Throwable

Reviewed By: achen1

Differential Revision: D7168684

fbshipit-source-id: c655730b5bf5e181974096c2b940f6457be8a40d
This commit is contained in:
David Vacca 2018-03-06 10:32:52 -08:00 committed by Facebook Github Bot
parent 6eef7de46e
commit d2f05740a8
1 changed files with 20 additions and 21 deletions

View File

@ -73,8 +73,8 @@ public class FabricUIManager implements UIManager {
mUIViewOperationQueue mUIViewOperationQueue
.enqueueCreateView(rootNode.getThemedContext(), reactTag, viewName, styles); .enqueueCreateView(rootNode.getThemedContext(), reactTag, viewName, styles);
return node; return node;
} catch (Exception e) { } catch (Throwable t) {
handleException(rootTag, e); handleException(getRootNode(rootTag), t);
return null; return null;
} }
} }
@ -103,8 +103,8 @@ public class FabricUIManager implements UIManager {
ReactShadowNode clone = node.mutableCopy(); ReactShadowNode clone = node.mutableCopy();
assertReactShadowNodeCopy(node, clone); assertReactShadowNodeCopy(node, clone);
return clone; return clone;
} catch (Exception e) { } catch (Throwable t) {
handleException(node.getThemedContext(), e); handleException(node, t);
return null; return null;
} }
} }
@ -120,8 +120,8 @@ public class FabricUIManager implements UIManager {
ReactShadowNode clone = node.mutableCopyWithNewChildren(); ReactShadowNode clone = node.mutableCopyWithNewChildren();
assertReactShadowNodeCopy(node, clone); assertReactShadowNodeCopy(node, clone);
return clone; return clone;
} catch (Exception e) { } catch (Throwable t) {
handleException(node.getThemedContext(), e); handleException(node, t);
return null; return null;
} }
} }
@ -140,8 +140,8 @@ public class FabricUIManager implements UIManager {
updateProps(clone, newProps); updateProps(clone, newProps);
assertReactShadowNodeCopy(node, clone); assertReactShadowNodeCopy(node, clone);
return clone; return clone;
} catch (Exception e) { } catch (Throwable t) {
handleException(node.getThemedContext(), e); handleException(node, t);
return null; return null;
} }
} }
@ -161,9 +161,8 @@ public class FabricUIManager implements UIManager {
updateProps(clone, newProps); updateProps(clone, newProps);
assertReactShadowNodeCopy(node, clone); assertReactShadowNodeCopy(node, clone);
return clone; return clone;
} catch (Exception e) { } catch (Throwable t) {
handleException(node.getThemedContext(), e); handleException(node, t);
getRootNode(1).getThemedContext().handleException(e);
return null; return null;
} }
} }
@ -191,8 +190,8 @@ public class FabricUIManager implements UIManager {
viewsToAdd, viewsToAdd,
null null
); );
} catch (Exception e) { } catch (Throwable t) {
handleException(parent.getThemedContext(), e); handleException(parent, t);
} }
} }
@ -227,7 +226,7 @@ public class FabricUIManager implements UIManager {
mUIViewOperationQueue mUIViewOperationQueue
.dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis()); .dispatchViewUpdates(1, System.currentTimeMillis(), System.currentTimeMillis());
} catch (Exception e) { } catch (Exception e) {
handleException(rootTag, e); handleException(getRootNode(rootTag), e);
} }
} }
@ -332,16 +331,16 @@ public class FabricUIManager implements UIManager {
} }
} }
private void handleException(ThemedReactContext context, Exception e) { private void handleException(ReactShadowNode node, Throwable t) {
try { try {
context.handleException(e); ThemedReactContext context = node.getThemedContext();
// TODO move exception management to JNI side, and refactor to avoid wrapping Throwable into
// a RuntimeException
context.handleException(new RuntimeException(t));
} catch (Exception ex) { } catch (Exception ex) {
Log.e(TAG, "Exception while executing a Fabric method", e); Log.e(TAG, "Exception while executing a Fabric method", t);
throw new RuntimeException(ex.getMessage(), e); throw new RuntimeException(ex.getMessage(), t);
} }
} }
private void handleException(int rootTag, Exception e) {
handleException(getRootNode(rootTag).getThemedContext(), e);
}
} }