Try Catch

Buen da.

Estoy desarrollando un aplicacin web con xojo 2015 Release 2.4, con Postgresql 9.4 sobre Linux , tambien estoy usando los webalert y tooltips de graffity.

En un webpage tengo declarado varias propiedades entre ellas:
RntExc de tipo RuntimeException
ErrMsg de tipo String

En el Open inicializo la propiedad error
self.RntExc = new RuntimeException

En el proceso de grabacin tengo este cdigo:

if Self.ValidaDatos = False Then Return

Self.ErrMsg = “”
Self.RntExc.ErrorNumber = -1

Try
Session.pasaDB.SQLExecute(“BEGIN TRANSACTION”)
Self.GrabarDocumento()
Session.pasaDB.Commit

MsgBox "Documento grabado..."
LimpiarVentana()

Catch
Session.pasaDB.Rollback
MsgBox “Error grabando documento” +EndOfLine + Self.ErrMsg
End Try

Metodo.GrabarDocumento
dim sql As string
sql = “INSERT INTO sistema.dominios (data) VALUES(’”+ Txtdominio.Text+"’)"
Session.pasaDB.SQLExecute(sql)
if Session.pasaDB.Error then
self.ErrMsg = “Error insertando sistema.dominios” + EndOfLine + Session.pasaDB.ErrorMessage
Raise Self.RntExc
End if

Self.GrabarDocumento_2
Self.GrabarDocumento_3

'fin del metodo GrabarDocumento

Metodo.GrabarDocumento_1
dim sql As string
sql = “INSERT INTO sistema.documento(campo1, campo2) VALUES(‘1’, ‘2’)”
Session.pasaDB.SQLExecute(sql)
if Session.pasaDB.Error then
self.ErrMsg = “Error insertando sistema.dominios” + EndOfLine + Session.pasaDB.ErrorMessage
Raise Self.RntExc
End if

Al ejecutar la aplicacin el mtodo GrabarDocumento_2 tiene un error, lo capturo y lanzo el error, lo espero es que el control lo tome el Catch, pero la aplicacin deja de funcionar, lo peor es que el algunos casos los registros se insertan y se actualizan las tablas involucradas, sin haber realizado el commit.

El try catch funciona en aplicaciones web, es la manera correcta de aplicarlo?
En aplicaciones de escritorio funciona bien.

Alguna sugerencia para asegurar la transaccin.

Saludos.
Mauricio

  1. this code
MsgBox "Documento grabado..."
LimpiarVentana()
Catch 

will catch ALL errors - not just the ones you raise in your code
You might want to create a custom subclass of RuntimeException and raise that so you can distinguish between ones the framework raises and one you raise

  1. There’s no reason try catch shouldn’t work
    Where are these methods (part of the web page or somewhere else) ?
    Thats important as it influences what “self” means

Hello Norman.

I’m going to create custon subclass of RuntimeException.

These methods are part of web page.

I will try something smaller to see if it works

Thanks
Mauricio

Based on what you posted I cant see an reason this should not be working as described
But there may be other bits in the application that I’m not seeing or aware of that affect this