Repository: flutter
Issue: [go_router] exceptions thrown during build does not trigger the errorPageBuilder
Labels: c: crash,package,has reproducible steps,P2,p: go_router,found in release: 3.10,found in release: 3.11,team-go_router,triaged-go_router

Using Flutter 3.10.0 and go_router 7.0.1

### Steps to reproduce

1.  In a goRoute build, throw a custom exception MyCustomRoutingException
2.  In  the errorPageBuilder, try to check if exception is of type MyCustomRoutingException

### Expected results

Expected to call ErrorBuilder when an error occurs. 

This was working with go_router v3.1.1

The change was made here in this [commit](https://github.com/flutter/packages/commit/c3b436ccf0ff8012de3796144ee995e713cd8046#r113179052).

### Actual results

Error gets passed up in main.dart

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  final GoRouter router = GoRouter(
    routes: [
      GoRoute(
        path: '/',
        pageBuilder: (context, state) {
          throw const CustomRoutingError();
        },
      ),
    ],
    errorPageBuilder: (context, state) {
      if (state.error is CustomRoutingError) {
        return const MaterialPage<void>(
          key: ValueKey('error_page'),
          child: Center(
            child: Text('Custom Routing Error'),
          ),
        );
      }
      return const MaterialPage<void>(
        key: ValueKey('error_page'),
        child: Center(
          child: Text('Unknown Error'),
        ),
      );
    },
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routeInformationProvider: router.routeInformationProvider,
      routeInformationParser: router.routeInformationParser,
      routerDelegate: router.routerDelegate,
      backButtonDispatcher: router.backButtonDispatcher,
    );
  }
}

class CustomRoutingError implements Exception {
  const CustomRoutingError();
}

```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.22621.1702], locale en-CH)
    • Flutter version 3.10.0 on channel stable at C:\src\flutter_2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 84a1e904f4 (4 days ago), 2023-05-09 07:41:44 -0700
    • Engine revision d44b5a94c9
    • Dart version 3.0.0
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at C:\Users\morat\AppData\Local\Android\sdk
    • Platform android-33, build-tools 32.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop for Windows (Visual Studio Build Tools 2017 15.9.38)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
    • Visual Studio Build Tools 2017 version 15.9.28307.1622
    • Windows 10 SDK version 10.0.17763.0
    X Visual Studio 2019 or later is required.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code, 64-bit edition (version 1.78.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.64.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.1702]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 113.0.5672.93
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 112.0.1722.68

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>