Skip to content

Exceptions

Exceptions are runtime errors that can be caught and handled.

Use lanzar to throw an exception with a message.

numero dividir(numero a, numero b) {
si (b == 0) {
lanzar "Division by zero is not allowed"
}
retornar a / b
}

When catching an exception, you have access to:

PropertyDescription
mensajeThe error message
llamadasCall stack as a list
capturar (excepcion e) {
texto mensaje = e.mensaje
lista pila = e.llamadas
}

The interpreter throws exceptions for:

  • Division by zero
  • Index out of range
  • Type conversion errors
  • Invalid JSON parsing
  • Access to non-existent properties
  • File system errors (when permissions enabled)
  • Use descriptive error messages
  • Include context in error messages
  • Throw exceptions for exceptional conditions, not flow control
  • Document what exceptions a function might throw