Repository: flutter
Issue: [local_auth] Improve exception handling of `local_auth` plugin
Labels: p: local_auth,package,c: proposal,team-ecosystem,P3,p: requires breaking change,triaged-ecosystem

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Use case

The `local_auth` plugin can throw a wide variety of exceptions. All of those exceptions are `PlatformException`s. That means, that you as a developer have to write code to decide based on the `PlatformException.code` on how to handle that error.

There's a file which contains a lot of those [error codes](https://github.com/flutter/plugins/blob/e6184f9cca0139ad3a45c212c2189b928b4e690d/packages/local_auth/local_auth/lib/error_codes.dart), but the don't contain all possible error code. That can be seen by comparing the error code used in [this file](https://github.com/flutter/plugins/blob/e6184f9cca0139ad3a45c212c2189b928b4e690d/packages/local_auth/local_auth_android/android/src/main/java/io/flutter/plugins/localauth/LocalAuthPlugin.java) for example.

Even the [example](https://pub.dev/packages/local_auth/example) for the package, doesn't really teach you how to handle all the exception cases and just does generic catch all error handling.

Additionally, adding different exceptions for different error cases, makes it easier to monitor in error monitoring software, because they're not grouped together with other `PlatformException`s.
 
## Proposal

<!--
     Briefly but precisely describe what you would like Flutter to be able to do.

     Consider attaching something showing what you are imagining:
      * images
      * videos
      * code samples

     Does this have to be provided by Flutter directly, or can it be provided
     by a package on pub.dev/flutter? If so, maybe consider implementing and
     publishing such a package rather than filing a bug.
-->

Introduce specific exceptions for all the different error codes. 

The following is an example of how I image it, for the `isDeviceSupported()` method. All the other methods should follow a similar pattern.

```dart
/// Returns true if device is capable of checking biometrics or is able to
/// fail over to device credentials.
Future<bool> isDeviceSupported() async {
  try {
    LocalAuthPlatform.instance.isDeviceSupported();
  } on PlatformException catch (exception, stackTrace) {
    Error.throwWithStackTrace(_convertException(exception), stackTrace);
  }
}

Object _convertException(PlatformException e) {
  switch (e.code) {
    // Taken from https://github.com/flutter/plugins/blob/e6184f9cca0139ad3a45c212c2189b928b4e690d/packages/local_auth/local_auth/lib/error_codes.dart#L13
    case 'NotEnrolled': return NotEnrolledException();
    // handle all the other error codes
  }
} 
```