Day 14 Of Flutter - Handling Exceptions

Table of contents

For day 14, I practised more of what I learned in my previous blog, although I also learned a few new things.

  • I created a login view using the same logic behind my user register view.

  • Took the register and login view from the main file and set them into their files.

  • Used my main dart file for FirebaseApp initialisation to serve as a way to route users to a view based on their login status.

Handling Exceptions

An exception is an unexpected error that occurs during the execution of an app and causes the app to act abnormally. An exception can occur if a user enters invalid data. This has to be handled to inform the user about it rather than letting the app break down without reason.

Exceptions are handled using try-catch blocks. The try block contains the code that may throw an exception, while the catch block manages the exception and provides a way for the app to recover. There are types of exceptions, and a try-catch block can be given a type of exception to handle.

So I handled some of the FirebaseAuthExceptions for the register and login views of the notes app. An example of a try-catch block meant to manage a FirebaseAuthException;

try {
// code for the function that could throw an exception error
} on FirebaseAuthException catch (e) {
// handle exception
}