Gambas/Manejo de Errores
< Gambas
- DEBUG Imprime un mensaje de depuración.
- FINALLY Ejecuta un bloque de código en una función, incluso si se produjo un error.
- CATCH Atrapa un error en una función.
- Error La clase estática Error.
- TRY Trata de ejecutar una instrucción sin levantar un error.
- ERROR Regresa TRUE si un error ha ocurrido, se usa justo después de TRY para saber si la instruccion ejecutada fallo.
DEBUG[editar]
FINALLY[editar]
Error[editar]
TRY[editar]
ERROR[editar]
CATCH[editar]
TRY – ERROR – CATCH – FINALLY trabajando juntos[editar]
'Prints a file to the screen SUB PrintFile(FileName AS STRING) DIM hFile AS File DIM sLig AS STRING OPEN FileName FOR READ AS #hFile WHILE NOT EOF(hFile) LINE INPUT #hFile, sLig PRINT sLig WEND FINALLY 'Always executed, even if a error is raised CLOSE #hFile CATCH 'Executed only if there is an error PRINT "Cannot print file "; FileName END
Enfoque proactivo a los errores (anticiparse a los errores)[editar]
Siempre es una buena idea, anticiparse a los errores