Answers for "catch error flutter"

0

try except flutter

try {
  print(x);
} on Exception catch (_) {
  print('never reached');
}
Posted by: Guest on July-18-2021
0

flutter error example

class MyApp extends StatelessWidget {
...
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      ...
      builder: (BuildContext context, Widget widget) {
        Widget error = Text('...rendering error...');
        if (widget is Scaffold || widget is Navigator)
          error = Scaffold(body: Center(child: error));
        ErrorWidget.builder = (FlutterErrorDetails errorDetails) => error;
        return widget;
      },
    );
  }
}
Posted by: Guest on December-23-2020
0

http exception flutter

// models/http_exception.dart
class HttpException implements Exception {
  final String message;

  HttpException(this.message);

  @override
  String toString() {
    return message;
  }
}


// in some other file
if (json.decode(response.body)['error'] != null) {
  throw HttpException(json.decode(response.body)['error']['message']);
}

// in ui file
try{

} on HttpException catch(error) {

} catch (error) {
  
}
Posted by: Guest on July-12-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language