In my case it made most sense to just throw the Exception inside the try catch block. I want to do this because I want to make sure that a user is logged in and don't want to handle a nullable User object.
@override
void onNavigation(NavigationResolver resolver, StackRouter router) {
try {
final user = ref.watch(firebaseAuthProvider).currentUser;
if (user == null) {
throw UserNotSignedInException();
}
resolver.next();
} on UserNotSignedInException {
logger('User is not logged in, pushing intro route', name: 'IntroGuard');
router.push(const IntroRoute());
} catch (e, s) {
logger(
'Error navigating to intro route',
error: e,
stackTrace: s,
name: 'IntroGuard',
);
router.push(const IntroRoute());
}
}