Skip to main content

Debugging Strategies

Systematic approaches to identifying and fixing errors in Kexra programs.

Why this exists

Debugging is essential for developing reliable software, and structured strategies make the process more efficient.

How it works

Use logging, error inspection, and incremental testing to isolate issues. The REPL provides an interactive environment for testing code snippets.

Examples

# Add logging to trace execution
fn problematicFunction(x) {
say "Entering function with x = " + x
set result = x * 2
say "After multiplication: " + result
check result > 100 {
throw "Result too large"
}
return result
}

# Test in REPL
# kex
# > set test = problematicFunction(60)
# Entering function with x = 60
# After multiplication: 120
# Error: Result too large

# Isolate the issue
fn safeMultiply(a, b) {
try {
return a * b
} catch error {
say "Multiplication failed: " + error
return 0
}
}

Common mistakes

  • Not logging intermediate values
  • Testing entire programs instead of isolating components
  • Ignoring error messages and stack traces