class MyCrashTestApp extends StatelessWidget {@overrideWidget build(BuildContext context) {return MaterialApp(home: Scaffold(appBar: AppBar(title: const Text('APM Exception Capture Test')),body: Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: [// 1. Synchronous exception testElevatedButton(child: const Text('Trigger Synchronous Exception'),onPressed: () => _throwSyncException(),),const SizedBox(height: 20),// 2. Asynchronous exception testElevatedButton(child: const Text('Trigger Asynchronous Exception'),onPressed: () => _throwAsyncException(),),const SizedBox(height: 20),// 3. Widget build exceptionElevatedButton(child: const Text('Trigger Widget Exception'),onPressed: () => Navigator.push(context,MaterialPageRoute(builder: (_) => FaultyWidget())),),],),),),);}// Synchronous exception examplevoid _throwSyncException() {// Simulates a business logic error.final list = [];print(list[0]); // Out-of-bounds access}// Asynchronous exception exampleFuture<void> _throwAsyncException() async {await Future.delayed(Duration(milliseconds: 500));// Simulates an asynchronous error.dynamic nullObject = null;print(nullObject.length); // NoSuchMethodError}}// Exception-throwing Widgetclass FaultyWidget extends StatelessWidget {@overrideWidget build(BuildContext context) {// Intentionally throws an exception during build.if (DateTime.now().millisecond % 2 == 0) {return Container(color: Colors.blue);}throw Exception('Random exception during Widget build');}}


Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback