Exception handling in Android games
Exception handling may not be a part of debugging, but it helps reduce the number of exceptions and unnecessary application crashes.
Exception handling in Android is the same as Java exception handling.
Syntax
Standard Java syntax for exception handling is as follows:
try { // Handled code here } catch (Exception e) { // Put debug statement with exception reason } finally { // Default instruction if any }
The suspicious code should be put inside a try
block, and the exception should be handled in a catch
block. If the module requires some default task to execute, then put it in the finally
block. The catch
and finally
blocks might not be defined always in exception handling. However, it is recommended that you process the exception in each try
block failure, which is a good programming practice. This process requires you to analyze the module to find out any vulnerable chunk of code.
Here is a simple example of handling exception along with other vulnerable...