From 81d33b1914965acf6183f19048a5a2da25dc5649 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Fri, 19 Sep 2025 10:44:38 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0try/catch=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/ImageSwitch.ets | 35 ++++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/entry/src/main/ets/pages/ImageSwitch.ets b/entry/src/main/ets/pages/ImageSwitch.ets index b7bb155..f83e47b 100644 --- a/entry/src/main/ets/pages/ImageSwitch.ets +++ b/entry/src/main/ets/pages/ImageSwitch.ets @@ -16,6 +16,8 @@ import { DataSource, PhotoData } from '../util/DataSource'; import { CommonConstants } from '../common//CommonConstants'; import { display, window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Component export struct ImageSwitch { @@ -35,17 +37,22 @@ export struct ImageSwitch { // [Start aboutToAppear] aboutToAppear(): void { - this.isFoldable = display.isFoldable(); - // Get the foldable screen status - let foldStatus: display.FoldStatus = display.getFoldStatus(); - if (this.isFoldable) { - this.foldStatus = foldStatus; - let callback: Callback = () => { - let data: display.FoldStatus = display.getFoldStatus(); - this.foldStatus = data; + try { + this.isFoldable = display.isFoldable(); + // Get the foldable screen status + let foldStatus: display.FoldStatus = display.getFoldStatus(); + if (this.isFoldable) { + this.foldStatus = foldStatus; + let callback: Callback = () => { + let data: display.FoldStatus = display.getFoldStatus(); + this.foldStatus = data; + } + // Monitor the changes in the unfolded status of the foldable screen + display.on('change', callback); } - // Monitor the changes in the unfolded status of the foldable screen - display.on('change', callback); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ImageSwitch', `getFoldStatus failed. code=${err.code}, message=${err.message}`); } let list: PhotoData[] = []; for (let i = 1; i <= 7; i++) { @@ -62,7 +69,9 @@ export struct ImageSwitch { statusBarColor: '#000000', statusBarContentColor: '#ffffff' }; - windowClass?.setWindowSystemBarProperties(sysBarProps); + windowClass?.setWindowSystemBarProperties(sysBarProps).catch((error: BusinessError) => { + hilog.error(0x0000, 'ImageSwitch', `setWindowSystemBarProperties failed. code=${error.code}, message=${error.message}`); + }); // [EndExclude aboutToAppear] } // [Start aboutToAppear] @@ -73,7 +82,9 @@ export struct ImageSwitch { statusBarColor: '#ffffff', statusBarContentColor: '#000000' }; - windowClass?.setWindowSystemBarProperties(sysBarProps); + windowClass?.setWindowSystemBarProperties(sysBarProps).catch((error: BusinessError) => { + hilog.error(0x0000, 'ImageSwitch', `setWindowSystemBarProperties failed. code=${error.code}, message=${error.message}`); + }); } // [Start progress_component] -- Gitee