3.1 Checking of mobile application source code
Checking source code means reading, reviewing and verifying the code of a mobile application before and during testing, so that faults are found at the place where they are written and not by users after release. A careful check looks at whether the code handles failures safely, follows agreed standards, is easy to read and can be traced from one version to the next. For example, a pharmacy chain's ordering app may work perfectly on the developer's phone, yet crash on a customer's phone when the network drops in the middle of an order. A systematic check of the source code would have revealed that the network call had no failure handling. This topic covers two practices: handling errors inside the code, and revising the code through review and version control.
3.1.1 Error handling techniques
Error handling is the set of coding practices that detect a problem, respond to it safely and tell the user or developer what happened, without the application crashing or corrupting data. Mobile apps are especially exposed to errors because phones lose network coverage, run low on memory and storage, are interrupted by calls, and receive unexpected input from users. Good error handling keeps the app usable and protects the user's data. Example: a SACCO member app that requests a loan balance should show "No connection, please try again" when the network fails, and not close suddenly.
Types of errors in mobile application code
Knowing the type of error helps a developer choose the right technique to handle it.
- Syntax errors: The code breaks the rules of the language, such as a missing bracket or misspelt keyword. The compiler or editor normally rejects the code, so the app cannot be built until it is corrected.
- Runtime errors: The code compiles but fails while running, for example dividing by zero, reading a null value, or opening a file that does not exist. These are the errors that crash apps in users' hands.
- Logic errors: The code runs without crashing but gives wrong results, for example a discount calculated on the wrong amount. These are the hardest to see because no error message appears.
- Resource errors: The device cannot supply what the app needs, such as network, storage, memory, camera or location permission. They depend on the phone and its condition, so they must always be expected.
- External service errors: A server, payment gateway or other service returns a failure, a timeout or data in an unexpected format. The app has no control over these, so it must respond to them gracefully.
Core error handling techniques
- Try-catch-finally blocks: Code that may fail is placed in a try block, the failure is caught in a catch block, and cleanup such as closing a file or database connection is placed in a finally block. Catch specific exception types before general ones so that each problem receives the right response.
- Input validation: Data is checked for presence, type, length and range before it is used. For example, a hospital appointment app should reject a date in the past and a phone number with the wrong number of digits before sending anything to the server.
- Null safety and defensive checks: The code tests whether a value exists before using it, and uses the language's safe features, such as nullable types and safe-call operators, to avoid null reference crashes.
- Custom exceptions and error codes: Developers define their own error types, such as InsufficientFundsException, so that each failure has a clear meaning and can be handled in a specific way. Result objects that carry either a success value or an error are an alternative to throwing exceptions.
- Meaningful user messages: The user sees short, plain guidance on what to do next, such as "Check your internet connection and try again". Technical details such as stack traces are never shown to the user.
- Logging: The code records the error type, a message, the time and the place where it occurred, so developers can investigate later. Passwords, PINs, card numbers and other sensitive data must never be written to logs.
- Timeouts and retries: Network requests are given a time limit, and may be repeated a limited number of times with increasing waits between attempts. Retrying forever drains the battery and may duplicate transactions, so retries must have a limit.
- Graceful degradation and fallbacks: When a feature fails, the app continues with reduced function, for example showing saved data from the last successful update. Example: a farm records app can show yesterday's milk collection figures from local storage when the server cannot be reached.
- Asynchronous error handling: Background tasks, callbacks, promises and coroutines need their own error handling, because an exception thrown in the background does not reach the try block in the main code.
- Global exception handlers: A last line of defence catches any error not handled elsewhere. It records the failure and shows a safe message or restarts the screen, instead of letting the app close without explanation.
Example of error handling in source code
The Kotlin function below validates its input, handles a network failure and a server failure separately, and returns a clear message.
fun loadBalance(memberId: String?): String {
if (memberId.isNullOrBlank()) {
return "Enter a valid member number"
}
return try {
val balance = api.getBalance(memberId)
"Balance: Ksh. $balance"
} catch (e: IOException) {
Log.w("Balance", "Network failure", e)
"No connection. Check your internet and try again"
} catch (e: HttpException) {
Log.e("Balance", "Server returned ${e.code()}", e)
"Service is busy. Please try again later"
} finally {
progressBar.visibility = View.GONE
}
}
Checking error handling in source code
When reviewing code, follow these steps to confirm that errors are handled properly.
- List the risk points: Mark every place where the code reads user input, calls a network or server, reads or writes storage, uses a sensor or permission, or parses data. These are the places where failures begin.
- Check that each risk point is protected: Confirm that every risk point sits inside a try-catch block or has a validation check before it. An unprotected network call is a defect.
- Check the catch blocks: Make sure specific exceptions are caught, and that no catch block is empty. An empty catch block hides a failure and makes later debugging very difficult.
- Check the user messages: Confirm that each failure produces a clear, polite message with a next step, and that no technical detail or sensitive data is displayed.
- Check the logging: Confirm that errors are recorded with enough detail to trace them, and that no passwords, PINs or personal data are logged.
- Check resource cleanup: Verify that files, database connections and listeners are closed in a finally block or by the language's automatic resource features, even when an error occurs.
- Check retries and timeouts: Confirm that every network request has a timeout and that retries are limited, so the app cannot hang or repeat a payment.
- Record and correct findings: Write each weakness with its file and line, correct it, and run the app again with the failure conditions, such as airplane mode or invalid input, to confirm the new behaviour.
3.1.2 Source code revision
Source code revision is the continuing process of reviewing, improving and tracking changes to the code so that every version is correct, readable and recoverable. It has two parts: human review of the code by other developers, and version control, which records who changed what, when and why. Revision matters because mobile apps are changed repeatedly, and an unrecorded change can introduce a fault that nobody can trace. Example: a county revenue collection app is updated every month, and version control lets the team see exactly which change broke the receipt screen and return to the last working version.
Code review
In a code review, one or more developers other than the author read the changes and comment before they are accepted into the main code. Reviews catch logic mistakes, security weaknesses and unclear code that the author no longer notices. Reviewers should check the following points.
- Correctness: The code does what the requirement says, including special cases such as empty lists, zero values and missing data.
- Error handling: Failures are caught and handled as set out in the techniques above.
- Readability: Names of variables and functions describe their purpose, functions are short and do one task, and comments explain why something is done and not only what.
- Coding standards: Indentation, naming style and file organisation follow the team's agreed standard, which keeps the whole codebase consistent.
- Security: No passwords, keys or tokens are written directly in the code, user data is stored and sent safely, and permissions requested are only those the app needs.
- Performance and resources: There are no unnecessary loops, repeated network calls, or objects kept in memory after they are no longer needed.
- Duplication: Repeated code is moved into one reusable function, so a future correction is made in a single place.
Version control
Version control software, most commonly Git, stores every saved change of the code as a commit in a history. Developers work on branches, which are separate lines of work, and merge them into the main branch only after review. The commands in the table are the ones used most often in revision.
| Name |
Specification |
Use |
| git status |
Shows changed, staged and untracked files |
Check what has changed before saving a revision |
| git diff |
Shows line-by-line differences between versions |
Inspect exactly what was added or removed |
| git add |
Moves selected changes to the staging area |
Choose which changes go into the next commit |
| git commit -m "message" |
Saves staged changes with a description |
Record a revision in the project history |
| git branch / git checkout |
Creates and switches between branches |
Work on a feature or fix without disturbing the main code |
| git merge |
Combines one branch into another |
Bring reviewed work into the main branch |
| git log |
Lists past commits with author, date and message |
Trace when and why a change was made |
| git revert |
Creates a new commit that undoes an earlier one |
Remove a faulty change while keeping history intact |
| git stash |
Temporarily shelves uncommitted changes |
Switch tasks without losing unfinished work |
Procedure for revising source code
- Create a branch: Start from the latest main branch and create a branch named after the task, for example fix-login-timeout. This keeps unfinished work away from the stable code.
- Make small, focused changes: Change one thing at a time, such as one fix or one feature. Small changes are easier to review and easier to undo.
- Review your own changes: Use git diff to read every changed line, and remove leftover test code, unused variables and temporary messages.
- Commit with a clear message: Write a short message that states what changed and why, for example "Add timeout to loan balance request". Messages such as "changes" or "fix" give no help later.
- Submit for peer review: Push the branch and open a pull request, so that another developer can read the changes and comment against the review checklist.
- Respond to comments: Correct the points raised, commit the corrections and ask for the review again until the reviewer approves.
- Resolve merge conflicts if they appear: A conflict occurs when two developers changed the same lines. Open the marked file, decide which lines to keep, remove the conflict markers, then test and commit the result.
- Merge and tag the version: After approval, merge into the main branch and tag the release with a version number. Rerun the application to confirm that nothing else was affected.
Refactoring and version numbering
Refactoring is the improvement of the internal structure of code without changing what the app does. Examples include splitting a 200-line function into smaller ones, renaming unclear variables and removing duplicated blocks. It is done in small steps, and the app is run again after each step to confirm that behaviour is unchanged.
Versions are commonly numbered in the form major.minor.patch, for example 2.4.1. The major number rises when changes break compatibility with earlier versions, the minor number rises when new features are added, and the patch number rises for bug fixes. For example, a bank's mobile app moving from 2.4.1 to 2.4.2 signals a bug fix only, while 3.0.0 signals a major redesign.
Good revision practices
- Commit often: Frequent small commits give a detailed history and reduce the loss if a device fails.
- Never commit secrets: API keys, passwords and signing keys must be kept out of the repository, for example in protected configuration files that are excluded from version control.
- Protect the main branch: Require a review before anything is merged, so that no one can change the stable code unchecked.
- Keep a change log: Record the changes in each release in plain language. For example, a school fees app can note "Version 1.3.0: parents can now download a fee statement".
- Back up the repository: Keep the code on a remote server as well as on developers' computers, so a lost laptop does not mean lost work. A contractor delivering an app to a client can also hand over the full history as proof of work done.
The rest of this chapter
🔒Create a free account to open more of this chapter.
Free: practical guides, quick cards, workplace scenarios and more.
Create a free account 🔒3.2 Debugging tools
Debugging tools help a developer to see what a mobile application is really doing, so that a fault can be located and understood before it is fixed. Each tool answers a different kind of question: where does the logic go wrong, why is the screen slow, why does…
🔒3.3 Regression testing
Regression testing is the repeated running of previously passed tests after a change to a mobile application, to confirm that the change has not broken features that were already working. A change can be a bug fix, a new feature, a library update or a configur…
🔒3.4 Prepare debugging report
A debugging report is a written record of the faults found in a mobile application, how they were investigated, how they were fixed and how the fixes were confirmed. It turns the private work of a developer into evidence that testers, supervisors and clients c…
Chapter Practical Activities
Practical 1: Identify and Classify Mobile Application Errors
Software Development · Level 6
Mobile Application Development
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)
Type: Individual
INSTRUCTIONS TO CANDIDATE:
1. You are required to perform the following task:
i. Inspect the provided Android mobile application source code and classify all identified errors into syntax, runtime, logic, and UI/UX errors with a brief explanation for each.
2. You have been provided with the following resources for the practical task:
| Tools & Equipment | Materials |
|---|
| Computer with Windows 10 OS or higher | Sample Android mobile application source code with known errors |
| Android Studio IDE | |
| Java Development Kit (JDK) version 8 or higher | |
| Android SDK | |
| Visual Studio Code or Notepad++ | |
| Android Emulator or Android Device | |
⬇ PDFResources Required (Cutting List)
| S/N | Item | Quantity |
|---|
| 1 | Computer with Windows 10 OS or higher | 1 Pc per Candidate |
| 2 | Android Studio IDE | 1 Pc per Candidate |
| 3 | Java Development Kit (JDK) version 8 or higher | 1 Pc per Candidate |
| 4 | Android SDK | 1 Pc per Candidate |
| 5 | Visual Studio Code or Notepad++ | 1 Pc per Candidate |
| 6 | Android Emulator or Android Device | 1 Pc per Candidate or 1 sharable per 15 Candidates |
| 7 | Sample Android mobile application source code with known errors | 1 Set per Candidate |
⬇ PDFAssessor Guide
| Items to be Evaluated | Marks Available | Marks Obtained | Comments |
|---|
| TASK 1: Identification of Errors |
Candidate opens the provided source code in Android Studio or text editor (Award 2 marks for opening and navigating the code correctly) | 2 | | |
Candidate identifies syntax errors in the code (Award 1 mark for each correctly identified syntax error up to 4) | 4 | | |
Candidate identifies runtime errors through testing or code inspection (Award 1 mark for each correctly identified runtime error up to 4) | 4 | | |
Candidate identifies logic errors affecting app functionality (Award 1 mark for each correctly identified logic error up to 4) | 4 | | |
Candidate identifies UI/UX errors related to user interface and experience (Award 1 mark for each correctly identified UI/UX error up to 3) | 3 | | |
| Sub-Total | 17 | | |
| TASK 2: Classification and Explanation of Errors |
Candidate classifies each identified error under correct error type (Award 2 marks for each error type correctly classified and explained, max 8 marks) | 8 | | |
Candidate provides brief, clear explanations for each error type (Award 1 mark for each clear explanation up to 5) | 5 | | |
Candidate documents errors and explanations in a clear, organized manner (Award 1 mark for clear documentation per error type up to 5) | 5 | | |
| Sub-Total | 18 | | |
| PRODUCT CHECKLIST |
Complete list of errors identified matches provided known errors with correct classification and explanations (Award up to 10 marks for accuracy and completeness of error identification, classification, and explanation) | 10 | | |
| Sub-Total | 10 | | |
| GRAND TOTAL | 45 | | |
ASSESSMENT OUTCOME: ☐ Competent ☐ Not Yet Competent (competent if at least 50%)
Practical 2: Debug an Android application using Android Studio debugger
Software Development · Level 6
Mobile Application Development
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)
Type: Individual
INSTRUCTIONS TO CANDIDATE:
1. You are required to perform the following task:
i. Use Android Studio debugger to locate and identify errors in the provided Android application source code and prepare a debug APK.
2. You have been provided with the following resources for the practical task:
| Tools & Equipment | Materials |
|---|
| Computer installed with Windows 10 OS or higher | Provided Android application source code with intentional errors |
| Android Studio IDE installed | |
| Java Development Kit (JDK) | |
| Android SDK | |
| Android Emulator or Android Device | |
⬇ PDFResources Required (Cutting List)
| S/N | Item | Quantity |
|---|
| 1 | Computer installed with Windows 10 OS or higher | 1 Pc per Candidate |
| 2 | Android Studio IDE installed | 1 Pc per Candidate |
| 3 | Java Development Kit (JDK) | 1 Pc per Candidate |
| 4 | Android SDK | 1 Pc per Candidate |
| 5 | Android Emulator or Android Device | 1 Pc per Candidate |
| 6 | Provided Android application source code with intentional errors | 1 Set per Candidate |
⬇ PDFAssessor Guide
| Items to be Evaluated | Marks Available | Marks Obtained | Comments |
|---|
| TASK 1: Setup and Initialization |
Launched Android Studio and imported the provided Android application source code (Award 2 marks for successful project import and setup) | 2 | | |
Configured Android emulator or connected Android device for debugging (Award 2 marks for correct device/emulator setup) | 2 | | |
Built the project and identified compilation errors using Android Studio (Award 3 marks for identifying compilation errors) | 3 | | |
| Sub-Total | 7 | | |
| TASK 2: Debugging Process |
Set breakpoints at suspected error lines in the code using Android Studio debugger (Award 3 marks for correctly placing breakpoints) | 3 | | |
Used debugger to step through code and monitor variable values and program flow (Award 4 marks for effective use of step-over, step-into, and variable inspection) | 4 | | |
Identified logical errors and runtime exceptions in the application (Award 3 marks for correctly identifying logical/runtime errors) | 3 | | |
| Sub-Total | 10 | | |
| TASK 3: Error Correction and Testing |
Modified the source code to fix identified errors (Award 4 marks for appropriate and correct code changes) | 4 | | |
Rebuilt and ran the application to verify errors were fixed (Award 3 marks for successful rebuild and testing) | 3 | | |
Tested the application with different input scenarios to confirm functionality (Award 3 marks for comprehensive functional testing) | 3 | | |
| Sub-Total | 10 | | |
| TASK 4: Packaging |
Packaged the corrected application as a debug APK using Android Studio (Award 5 marks for successful APK packaging) | 5 | | |
| Sub-Total | 5 | | |
| PRODUCT CHECKLIST |
Debug APK runs without errors and produces expected output on Android emulator or device (Award 8 marks for error-free execution and correct results) | 8 | | |
| Sub-Total | 8 | | |
| GRAND TOTAL | 40 | | |
ASSESSMENT OUTCOME: ☐ Competent ☐ Not Yet Competent (competent if at least 50%)
🔒Debug an iOS mobile application using Xcode debugger to identify errorsPractical 3
🔒Debug React Native app using React Native debuggerPractical 4
🔒Debug Flutter mobile application using Flutter DevToolsPractical 5
🔒Isolate Runtime Error Causes in a Mobile ApplicationPractical 6
🔒Isolate and analyze logic errors in a mobile calculator appPractical 7
🔒Identify and fix UI/UX errors in a mobile application layout 1080px x 1920pxPractical 8
🔒Apply fixes to syntax errors in mobile application codePractical 9
🔒Test fixes applied to mobile application errorsPractical 10
🔒Implement logging functionality in a mobile applicationPractical 11
🔒Generate and Analyze Logs for Mobile Application DebuggingPractical 12
🔒Debug a Mobile Application Using Debugging ToolsPractical 13
🔒Compare debugging features of Android Studio, Xcode, React Native, and Flutter toolsPractical 14
🔒Monitor Mobile Application Performance Using Logs and Debugging ToolsPractical 15