camera: make exception handling more explicit in camera2 classes
Camera2 classes used CameraManager's `throwAsPublicFunction` as a catchall to wrap and re-throw binder exceptions to the applications. This is functionally correct, however it left some code paths ambiguous whether it would terminate the method or not. Consequently there were a few anti-pattern in the code, specifically: 1. Unreachable statements from compiler not realizing that calls to `throwAsPublicException` are terminal and no handling is needed after. 2. Methods catching Throwables only to pass it to `throwAsPublicFunction` which would finally re-throw it. Catching generic Throwables is only one step away from difficult to debug bugs and may hide larger issues. It is recommended to only catch exceptions intended to be handled. As more classes are getting added which rely on `throwAsPublicFunction` to wrap relevant exceptions into application facing exceptions, this CL moves the logic into a separate helper class, and breaks the method up to accept specific Exceptions rather than a generic `Throwable`. It also updates all usages of `throwAsPublicException` to ensure that callers are only handling the exceptions they expect to handle, and explicitly marks the call with `throw` to ensure that the compiler knows where execution will terminate preventing false error messages about missing return statements. Bug: 320741775 Test: No functional change. atest CtsCameraTestCases:CameraManagerTest passes atest CtsCameraTestCases:CameraDeviceTest passes Change-Id: Ic2b765961688ab1cd5e931d8a6ffca8b583d1952
Loading
Please register or sign in to comment