Skip to content

Commit 084730f

Browse files
fix: #2957 replaces throwing exception with returning default values (#3445)
1 parent 743bec6 commit 084730f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ library device_info_plus_windows;
33

44
import 'dart:ffi';
55
import 'dart:typed_data';
6+
import 'dart:developer' as developer;
67

78
import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart';
89
import 'package:ffi/ffi.dart';
@@ -124,8 +125,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
124125
if (result != 0) {
125126
return memoryInKilobytes.value ~/ 1024;
126127
} else {
127-
final error = GetLastError();
128-
throw WindowsException(HRESULT_FROM_WIN32(error));
128+
developer.log('Failed to get system memory', error: GetLastError());
129+
return 0;
129130
}
130131
} finally {
131132
free(memoryInKilobytes);
@@ -149,7 +150,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
149150
if (result != 0) {
150151
return lpBuffer.toDartString();
151152
} else {
152-
throw WindowsException(HRESULT_FROM_WIN32(GetLastError()));
153+
developer.log('Failed to get computer name', error: GetLastError());
154+
return "";
153155
}
154156
} finally {
155157
free(lpBuffer);
@@ -167,7 +169,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
167169
if (result != 0) {
168170
return lpBuffer.toDartString();
169171
} else {
170-
throw WindowsException(HRESULT_FROM_WIN32(GetLastError()));
172+
developer.log('Failed to get user name', error: GetLastError());
173+
return "";
171174
}
172175
} finally {
173176
free(pcbBuffer);

0 commit comments

Comments
 (0)