McBasic™Get McBasic™ ↗
Build 881
Guided workflow

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#

ObjectRequired configuration
txtName · TextBoxText empty; MultiLine False.
lblGreeting · LabelCaption empty.
cmdGreet · CommandButtonCaption 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.

Forms/frmMain.bas · caught-error variant
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 Sub

Save, 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.

Forms/frmMain.bas · unhandled-error variant
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 Sub

Run 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#

Forms/frmMain.bas · final replacement handler
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 Sub

Check 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.

Source baseline 20f4bfed6b · Build manifest
Sources & 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.md
  • docs/manual/15-check-test-and-debug.md
  • macos/McBasicIDE/Sources/AutoCheck.swift
  • macos/McBasicIDE/Sources/RunErrorNavigation.swift
  • src/McBasic.Build/DefinitionService.cs
  • src/McBasic.Runtime/McHandledErrors.cs
  • src/McBasic.Runtime/McRuntimeErrors.cs
  • src/McBasic.Runtime.UI/McRuntimeErrorDialog.cs
  • samples/HelloForms.mcbproj/Forms/frmMain.bas
  • samples/HelloForms.mcbproj/Forms/frmMain.form.json