3.4 · Error handling & debugging

Level 3 · Advanced: in-depth WLangage

3.4Error handling & debugging

Goal: Make the application robust with QUAND EXCEPTION and locate defects with the debugger and a reliable method.
Estimated time: 11 min · self-paced reading · If you only have 5 min: read “The essentials in 30s” + the diagram.

The essentials in 30 seconds

  • Three families of errors: compilation, runtime and functional — the last is the most dangerous because nothing signals it.
  • QUAND EXCEPTION intercepts a runtime error; HFSQL return values are also tested rather than assuming a write succeeded.
  • Debugging = reproduce, isolate, understand the real cause, fix then verify; on the user side, a clear message and logging.

Running mini-case — Yacine saves an order despite the outage

Yacine records an order for electrical equipment when the HFSQL server becomes unreachable. Without precautions, the application stops abruptly and the user loses their input. He wraps the write in QUAND EXCEPTION, tests the query's return and displays an understandable message: “Order not saved: server unavailable, check the network.” The technical detail goes to the log, not to the screen. Later, a wrong total appears on some orders: Yacine reproduces the case with the same lines, sets a breakpoint before the calculation, steps through it and discovers a line with no price. He notes the reflex: intercept, test, log, then reproduce and isolate before fixing.

Self-contained case for this section: it returns in the course, diagram, script and 48h challenge of section 3.4.

1. Three families of errors

Robust code never assumes everything will go well. A compilation error is detected before execution: syntax mistake, unknown name. A runtime error occurs during operation: division by zero, missing file, network down, insufficient rights. A functional error is the most dangerous: the program runs but the result is wrong, and nothing signals it. An incorrect total in one of Yacine's invoices belongs to this family.

2. Intercept and test

WLangage offers QUAND EXCEPTION to intercept a runtime error and take back control instead of letting the application crash. But interception does not replace checking: an HFSQL write can fail because of a duplicate, a constraint or a lock. Yacine tests the return values of functions, plans a fallback behaviour and displays an understandable message — never a raw technical code. The detail goes to the log for diagnosis.

3. A debugging method

The integrated debugger offers breakpoints, step-by-step execution, variable inspection and the call stack. The method matters as much as the tool: reproduce the problem reliably, isolate the scope, understand the real cause rather than the symptom, then fix and verify the absence of regression. A bug you cannot reproduce cannot be fixed with certainty.

Common misinterpretation: “A functional error is always visible; QUAND EXCEPTION is enough to protect everything; and debugging consists of changing the code at random until the symptom disappears”. No, three mistakes. The functional error is precisely invisible: the program runs and produces a wrong result. QUAND EXCEPTION intercepts a runtime error, but you must also test HFSQL return values and plan a fallback. And randomness is not a method: you reproduce, you isolate, you understand the real cause, then you fix and verify.
Debugging method Reproduce, isolate, understand, fix and verify. Reproduce reliablecaseIsolate scope andvariablesUnderstand real causeFix then verify
Reproduce, isolate, understand, fix and verify.
Text version of the diagram (SEO / screen readers / translation): 1) Yacine, a WinDev developer at an SME trading electrical equipment in Oran, sees an order write fail when the HFSQL server is unavailable. 2) He wraps the operation in QUAND EXCEPTION, tests the query's return, logs the technical detail and displays an understandable message to the user. 3) Faced with a wrong total, he reproduces the case with the same data, sets a breakpoint, steps through, isolates the line with no price, fixes the cause then verifies that no other order regresses. Lesson: intercepting and testing makes the code robust; the method, not chance, finds the cause.

🔎 Concrete example — 🔎 Concrete example — Intercept, log, understand

Yacine secures the recording of an order then tracks down a wrong total:

QUAND EXCEPTION DANS
    HExecuteRequete(Req_AjoutCommande)
    SI HEnDehors(Req_AjoutCommande) ALORS
        Erreur("La commande n'a pas pu etre enregistree.")
    FIN
FAIRE
    JournalAjoute("Erreur HFSQL commande", ErreurInfo())
    Info("Serveur indisponible : reessayez ou contactez le support.")
FIN

// Debugging: breakpoint before the calculation, then step by step
nTotal = CalculeTotalLignes(TAB_Lignes)

Reading: the user receives an action to take, the log keeps the technical detail.

Lesson: the breakpoint and stepping show where the value becomes wrong.

Section vocabulary

Runtime error
Error occurring during operation: missing file, network down, division by zero.

Simple example: Yacine's HFSQL query fails because the server is unavailable.

What it is not: a syntax mistake signalled before execution.

Reflex: crash during the action → runtime error.

QUAND EXCEPTION
WLangage mechanism that intercepts a runtime error to handle it cleanly.

Simple example: Yacine uses it around the order write.

What it is not: letting the application stop abruptly in front of the user.

Reflex: take back control → QUAND EXCEPTION.

Functional error
Situation where the program runs correctly but produces a wrong result.

Simple example: An invoice total is wrong because of a line with no price.

What it is not: an exception that visibly interrupts processing.

Reflex: wrong result without a crash → functional error.

Breakpoint
Marker placed in the code to suspend execution and inspect the state at that point.

Simple example: Yacine sets it before CalculeTotalLignes.

What it is not: a simple trace displayed after the end of processing.

Reflex: observe a suspect area → breakpoint.

Logging
Recording errors and technical events to diagnose afterwards.

Simple example: Yacine records the HFSQL error in the log without displaying it on screen.

What it is not: a raw technical message shown directly to the user.

Reflex: diagnose remotely → log.

In practice — In practice — Making your code robust and debugging

  1. Wrap risky operations (file, network, conversion, calculation) and test HFSQL return values, like Yacine.
  2. Set a breakpoint before the suspect area, step through and inspect the variables.
  3. Apply the method: reproduce, isolate, understand the real cause, fix then verify.
  4. Replace technical messages with an understandable message and log the detail for diagnosis.
Your application withstands the unexpected, informs the user correctly and has a reliable method to fix defects.

Step-by-step script — track down a wrong total like Yacine (4 min)

1) Reproduce the problem with the same data and the same actions. 2) Set a breakpoint before the suspect calculation and step through. 3) Inspect the variables: spot the line whose price is empty or badly converted. 4) Fix the real cause, not the symptom. 5) Verify the corrected case and the absence of regression on the other orders.

Keep this reflex: a bug that cannot be reproduced cannot be fixed with certainty.

Copy-paste template — Yacine's errors & debugging sheet

Errors     : compilation / runtime / functional (the most dangerous)
Intercept  : QUAND EXCEPTION + test HFSQL return values
User       : understandable message; technical detail in the log
Method     : reproduce -> isolate -> understand -> fix -> verify
Tools      : breakpoint, step by step, variables, call stack, trace

An unreachable server

Yacine intercepts the error, logs it and invites the user to try again.

A wrong total

Yacine reproduces, isolates the line with no price and fixes the real cause.

A raw message

Yacine replaces “Error 0x8004” with a clear and actionable message.

An intermittent bug

Yacine looks for what varies (volume, workstation, rights) to reproduce it reliably.

✓ Best practices

  • Always test the return values of risky operations.
  • Reproduce before fixing.
  • Display a clear message, log the detail.

✗ Common pitfalls

  • Assuming that an HFSQL write succeeded.
  • Fixing the symptom without the cause.
  • Showing a raw technical code to the user.

Key takeaways

  • Compilation, runtime and functional: three families with different consequences.
  • QUAND EXCEPTION intercepts; HFSQL return values are tested.
  • Debugging = reproduce, isolate, understand, fix, verify.
  • Understandable user message and logging of the technical detail.

48h challenge — apply it tomorrow

Like Yacine, wrap a risky operation of your application (HFSQL write, file read, conversion) in QUAND EXCEPTION, test its return and log the detail. Display an understandable message. Then take a real bug: reproduce it, set a breakpoint, step through and note in one sentence the real cause you found.

Section exit checklist
  • I distinguish compilation, runtime and functional errors.
  • I know how to intercept an error and test an HFSQL return value.
  • I apply a four-step debugging method.
Self-assessment 1-5: do I test return values instead of assuming?Self-assessment 1-5: do I look for the real cause, not the symptom?

Frequently asked questions

How do you handle an error without crashing the application?

By anticipating risky operations: file access, network, database, conversions. Wrap them with QUAND EXCEPTION, test return values, plan a fallback behaviour and log the technical detail. The user must receive an understandable and actionable message, never a raw technical code. For several related writes, a transaction avoids an inconsistent state.

What is the best method to find the origin of a bug?

Reproduce reliably, isolate the scope, understand the real cause, then fix and verify the absence of regression. The debugger — breakpoint, stepping, variable inspection — supports this method, it does not replace it. A bug you cannot reproduce cannot be fixed with certainty: always start with the exact conditions.

Check your understanding

What is the QUAND EXCEPTION mechanism for?

Additional resources (optional, to go further)

Level 3 examFresh, harder questions to test what you've learned