From 511fad3950db2733d573353aaae47d732684d7cc Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 23 Feb 2026 09:58:07 +0100 Subject: [PATCH] Remove try-catch from Button1/2_Click event handlers Refactored Button1_Click and Button2_Click to eliminate local try-catch blocks, allowing exceptions to propagate. Cleaned up redundant code and improved clarity by moving variable declarations outside of the previous try blocks. Core logic remains unchanged. --- EnvelopeGenerator.BBTests/frmFinalizePDF.vb | 65 +++++++-------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/EnvelopeGenerator.BBTests/frmFinalizePDF.vb b/EnvelopeGenerator.BBTests/frmFinalizePDF.vb index e6466c73..691a60ca 100644 --- a/EnvelopeGenerator.BBTests/frmFinalizePDF.vb +++ b/EnvelopeGenerator.BBTests/frmFinalizePDF.vb @@ -7,7 +7,6 @@ Imports GdPicture14 Imports Newtonsoft.Json.Linq Imports EnvelopeGenerator.Infrastructure Imports Microsoft.EntityFrameworkCore -Imports System.Text Imports DigitalData.Core.Abstractions Public Class frmFinalizePDF @@ -93,56 +92,36 @@ Public Class frmFinalizePDF End Function Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click - Try + Dim oTable = LoadAnnotationDataForEnvelope() + Dim oJsonList = oTable.Rows. + Cast(Of DataRow). + Select(Function(r As DataRow) r.Item("VALUE").ToString()). + ToList() - Dim oTable = LoadAnnotationDataForEnvelope() - Dim oJsonList = oTable.Rows. - Cast(Of DataRow). - Select(Function(r As DataRow) r.Item("VALUE").ToString()). - ToList() + Dim envelopeId As Integer = CInt(txtEnvelope.Text) + Dim oBuffer As Byte() = ReadEnvelope(envelopeId) + Dim oNewBuffer = PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, envelopeId) + Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf") - Dim envelopeId As Integer = CInt(txtEnvelope.Text) - Dim oBuffer As Byte() = ReadEnvelope(envelopeId) - Dim oNewBuffer = PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, envelopeId) - Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) - Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf") - - File.WriteAllBytes(oNewPath, oNewBuffer) - - Process.Start(oNewPath) - Catch ex As Exception - Dim exMsg As StringBuilder = New StringBuilder(ex.Message).AppendLine() - - Dim innerEx = ex.InnerException - While (innerEx IsNot Nothing) - exMsg.AppendLine(innerEx.Message) - innerEx = innerEx.InnerException - End While - - MsgBox(exMsg.ToString(), MsgBoxStyle.Critical) - End Try + File.WriteAllBytes(oNewPath, oNewBuffer) + Process.Start(oNewPath) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click - Try - Dim oTable = LoadAnnotationDataForEnvelope() - Dim oJsonList = oTable.Rows. - Cast(Of DataRow). - Select(Function(r As DataRow) r.Item("VALUE").ToString()). - Select(Function(s As String) JObject.Parse(s)). - ToList() - - Dim oJObject1 = oJsonList.First() - Dim oJObject2 = oJsonList.ElementAt(1) - - oJObject1.Merge(oJObject2) + Dim oTable = LoadAnnotationDataForEnvelope() + Dim oJsonList = oTable.Rows. + Cast(Of DataRow). + Select(Function(r As DataRow) r.Item("VALUE").ToString()). + Select(Function(s As String) JObject.Parse(s)). + ToList() - txtResult.Text = oJObject1.ToString() + Dim oJObject1 = oJsonList.First() + Dim oJObject2 = oJsonList.ElementAt(1) + oJObject1.Merge(oJObject2) - Catch ex As Exception - MsgBox(ex.Message, MsgBoxStyle.Critical) - End Try + txtResult.Text = oJObject1.ToString() End Sub End Class \ No newline at end of file