Trace a caught and an unhandled error
Practice live Check, Jump to Definition, Output evidence and Go to Line with complete, reversible first-app handlers.
Step 1Prepare an isolated first-app copy#
Use McBasic™ 0.5.840 or later. Download HelloForms, extract a new copy and open HelloForms.mcbproj. Keep Forms/frmMain.bas and its layout together. Do not use a production project. Save a clean baseline.
Step 2Confirm the properties and event binding#
| Object | Required configuration |
|---|---|
| txtName · TextBox | Text empty; MultiLine False. |
| lblGreeting · Label | Caption empty. |
| cmdGreet · CommandButton | Caption Greet; Click bound to cmdGreet_Click. |
Keep cmdDetails and its existing handler. Run Check and Run; Ada produces Hello, Ada and blank input produces Enter a name. Stop the app before editing.
Step 3Observe an unsaved diagnostic and remove it#
Enable Settings → Code → Check automatically. In cmdGreet_Click, replace only Len(name) with Len(missingName). Pause for about 1.2 seconds without saving. Read the error underline and Diagnostics entry. Restore Len(name) and wait for the current check to succeed. Run manual Check if another command delayed the background result.
Step 4Navigate to a different document#
In cmdDetails_Click, Command-click frmDetails in the Dim declaration, or place the caret there and press Shift–F2. Confirm that the Details Form opens in the Designer. Return to frmMain and use the code context menu to inspect a variable declaration. Read the status message if a name is ambiguous or has no project definition.
Step 5Catch a deliberate error and inspect Output#
Replace only cmdGreet_Click with this complete handler; keep Option Explicit and cmdDetails_Click.
Private Sub cmdGreet_Click()
' Raise a harmless practice error, then show that the handler recovered.
Try
Err.Raise 5, "RuntimePractice", "A deliberate practice error; no data was changed."
Catch failure As McException
lblGreeting.Caption = "Handled error " & CStr(failure.Number)
End Try
End SubSave, Check, Run and click Greet once. The Label becomes Handled error 5. Read the Handled runtime error line in Output and confirm the application remains responsive. Stop. This is a Run observation, not a unit-test result.
Step 6Remove the handler and use Go to Line#
Replace the same procedure with this variant. Check still succeeds: the deliberate failure happens only when the event runs.
Private Sub cmdGreet_Click()
' No handler here: use the IDE error dialog to locate this statement.
Err.Raise 5, "RuntimePractice", "A deliberate practice error; no data was changed."
End SubRun and click Greet. Expect runtime error 5 and the practice message. Copy the details if useful; Copy leaves the dialog open. Choose Go to Line. The app ends and the IDE opens the source at Err.Raise. The actual line number depends on the surrounding file; do not expect a fixed number from this page.
Step 7Restore the complete production behavior#
Private Sub cmdGreet_Click()
' Normalize input before deciding whether a greeting can be shown.
Dim name As String
name = Trim$(txtName.Text)
If Len(name) = 0 Then
lblGreeting.Caption = "Enter a name."
Exit Sub
End If
lblGreeting.Caption = "Hello, " & name
End SubCheck and Run again. Ada and surrounding spaces produce Hello, Ada; empty input and three spaces produce Enter a name. Verify Details still works. Save, close and reopen, then repeat the cases.
Step 8Choose what to share if you ask AI for help#
Editing to restore the handler invalidates the previous Run evidence. If you need a fresh report, reproduce it in a separate practice copy first. Before any Fix Send, inspect Show exact content and Last Run output. Removing that chip disables Run sharing for this chat, including future Runs, until you re-enable + Add → Last Run output (Fix). An Allow/Deny documents card is a separate decision about named source files; it does not restore Run sharing.
20f4bfed6b · Build manifestSources & maintenance
Original web explanation, reviewed against these repository sources. API tables and example files follow the implementation.
docs/manual/04-the-ide-at-a-glance.mddocs/manual/15-check-test-and-debug.mdmacos/McBasicIDE/Sources/AutoCheck.swiftmacos/McBasicIDE/Sources/RunErrorNavigation.swiftsrc/McBasic.Build/DefinitionService.cssrc/McBasic.Runtime/McHandledErrors.cssrc/McBasic.Runtime/McRuntimeErrors.cssrc/McBasic.Runtime.UI/McRuntimeErrorDialog.cssamples/HelloForms.mcbproj/Forms/frmMain.bassamples/HelloForms.mcbproj/Forms/frmMain.form.json