Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. The code in Figure 11-49 executes when a button is tapped or clicked on a Win

ID: 3852738 • Letter: 1

Question

1. The code in Figure 11-49 executes when a button is tapped or clicked on a Windows Form object. Identify what will happen when a single error occurs. What happens if two errors occur at the same time? What happens if three errors occur at the same time? How can this code be repaired?

Dim InputError As Boolean = False 20 21 If txtSocialSecurity MaskFull False Then MsgBox ("Enter your Student ID in the Student ID box",, "Error") txtSocialSecurity.clear ) txtSocialSecurity Focus() InputError True 23 24 25 26 27 28 29 30 31 32 End If 1 Or txt LastName Text "A" Then If txtLastName TextLength MsgBox ("Enter your name in the Student Name box",,rror) txtLastName.Clear () txtLastName. Focus() InputError-True 34 35 36 37 3 8 39 40 41 42 43 End If If Not IsNumeric (txtNumberofDependents.Text) Then MsgBox ("Enter the units in the Number of Units box, . " Error) txtNumberOfDependents.Clear ) txtNumberOfDependents Focus () InputError = True End If

Explanation / Answer

In the above code if single error the code after the line where error occured would not work. When two or three errors will arise at the same time only one of them is going to show. The other gets ignored itself. To correct the code try catch must be used in the code. For example,

Try

// after this add a statement

// then add the catch block with error

catch e As System.OverFlowException // overflow is an example, you must catch the type of error you think can occur

MsgBox( "Error")

// Another try block goes here:

Try

// then the condition here

catch e As System.ArgumentException // replace this with the second type of error

MsgBox("whatever you want to show")

// Again another try block to handle the third condition

Try

// 3rd condition

catch e As System.ArgumentOutOfRangeException // error you think which can occur

MsgBox("Msg of your choice")

// You must handle the error using try catch wherever you think their is a chance of error. By using this the whole system does not gets affected.

****Please please provide the CF score by liking the answer. Thanks in advance.