Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

wrap excel creation in try catch finally block - #43

Merged
Luciano Gonzalez (lgonzalez876) merged 2 commits into
microsoft:mainfrom
amao9098:main
Mar 10, 2022
Merged

wrap excel creation in try catch finally block#43
Luciano Gonzalez (lgonzalez876) merged 2 commits into
microsoft:mainfrom
amao9098:main

Conversation

@amao9098

Copy link
Copy Markdown
Collaborator

Wrapping excel file creation in try catch finally block in case exceptions/error out so that excel resources are still cleaned up.

@amao9098amao9098 linked an issue Mar 10, 2022 that may be closed by this pull request
Comment threadExcelPlotter.psm1
Fit-Cells -Worksheet $worksheetObject
Write-Progress -Activity "Creating Excel File" -Status "Done" -Id 4 -PercentComplete 100
} catch {
Write-Warning "Exception $($_.Exception.Message) in $($MyInvocation.MyCommand.Name)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with throw $_, no need for anything else in the catch block. This will cause the original error to be rethrown after the finally block, preserving the original error and context.

@lgonzalez876
Luciano Gonzalez (lgonzalez876) merged commit 01e1280 into microsoft:mainMar 10, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The EXCEL.exe process isn't always closed on exit

3 participants

@amao9098@tmolenh@lgonzalez876