Exceptions
Exceptions are runtime errors that can be caught and handled.
Throwing Exceptions
Section titled “Throwing Exceptions”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}Exception Properties
Section titled “Exception Properties”When catching an exception, you have access to:
| Property | Description |
|---|---|
mensaje | The error message |
llamadas | Call stack as a list |
capturar (excepcion e) { texto mensaje = e.mensaje lista pila = e.llamadas}Common Exceptions
Section titled “Common Exceptions”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)
Best Practices
Section titled “Best Practices”- Use descriptive error messages
- Include context in error messages
- Throw exceptions for exceptional conditions, not flow control
- Document what exceptions a function might throw