errorHandlingExample function
Error handling patterns
Implementation
Future<void> errorHandlingExample() async {
print('\n=== Error Handling Example ===');
final backend = QuicUIFirebase();
// Handle not initialized
try {
await backend.fetchScreen('some-screen');
} on NotInitializedException {
print('Backend not initialized - call initialize() first');
}
// Handle screen not found
try {
await backend.fetchScreen('non-existent-screen');
} on ScreenNotFoundException catch (e) {
print('Screen not found: $e');
}
// Handle network errors
try {
await backend.initialize();
await backend.fetchAllScreens();
} on NetworkException {
print('Network error - check internet connection');
}
// Handle invalid JSON
try {
await backend.saveScreen(
screenId: 'bad-json',
name: 'Bad JSON',
json: '{invalid json}', // This will be caught
);
} on InvalidJSONException {
print('Invalid JSON - check format');
}
// Generic error handling
try {
await backend.fetchScreen('some-screen');
} on QuicUIFirebaseException catch (e) {
print('QuicUI Firebase error: $e');
} catch (e) {
print('Unexpected error: $e');
}
}