Hi, I have a problem handling exceptions by try catch method.
When I capture the error, I don’t know how to avoid a error message to the user.
I nedd to avoid reporting errors to the user because this is an unattended process.
Regards
Hi, I have a problem handling exceptions by try catch method.
When I capture the error, I don’t know how to avoid a error message to the user.
I nedd to avoid reporting errors to the user because this is an unattended process.
Regards
if you click the solutionNode in the solution explorer, you will see a property ‘onErrorMethod’ in de properties pane.
You can let Servoy create the method for you and customise it the way you want it to behave.
Thanks for reply, but when I have using try catch sentence, the property onErrorMethod don’t throws.
Furthermore, onErrorMethod return a boolean (//if returns false or no return, error is not reported to client; if returns true error is reported by default error report means logging the error, in smart client an error dialog will also show up), but don’t works correctly because an error dialog shows up and need a user interaction.
I need use the try catch sentence because I do not want exit to program, I want continue execution.
What do you think about that?
Regards
If you are wrapping whatever is throwing the exception in a try/catch statement, then the user should not be seeing any error unless you are specifically re-throwing the error.
This code will catch any exceptions thrown by “unsafeFunction” and the user should not see anything.
function triggeredByUser() {
try {
unsafeFunction()
}
catch (e)
{
//Do nothing here and user should be fine
}
}
If this is not the behavior you are seeing, post some sample code of what isn’t working.
This is a try catch example:
try {
//Unsafe Code
}catch (e) {
//Para cualquier fallo en la ejecución del método
if (e != null) {
var codigo = "0";
var hoy = application.getTimeStamp();
var mensaje = e;
if (e.isServoyException) {
codigo = e.getErrorCode();
mensaje = e.getMessage();
}
//Guardamos el error en el log
textoLog = 'ERROR en la impresión de los datos de Esterilidad de la historia: '+foundset.nhc_vc+' -- ' + e + '\n\n';
plugins.file.appendToTXTFile(log, textoLog);
}
}
and this is the function on ErrorMethod (for hide dialogs if is needed):
function onError(ex) {
//this sample script should be attached to onError method handler in the solution settings
var textoLog = 'ERROR -- Exception Object: ' + ex +'\n';
textoLog += 'MSG: ' + ex.getMessage()+'\n';
if (ex instanceof ServoyException) {
/** @type {ServoyException} */
var servoyException = ex;
textoLog += "is a ServoyException\n";
textoLog += "Errorcode: " + servoyException.getErrorCode()+'\n';
var trace = "";
if (ex.getStackTrace()) trace = servoyException.getStackTrace();
else if (servoyException.getStackTrace()) trace = servoyException.getStackTrace();
textoLog += '\n'+trace+'\n';
if (servoyException.getErrorCode() == ServoyException.SAVE_FAILED) {
//Get the failed records after a save
var array = databaseManager.getFailedRecords()
for (var i = 0; i < array.length; i++) {
var record = array[i];
textoLog += record.exception+'\n';
if (record.exception instanceof DataException) {
/** @type {DataException} */
var dataException = record.exception;
textoLog += 'SQL: ' + dataException.getSQL()+'\n';
textoLog += 'SQLState: ' + dataException.getSQLState()+'\n';
textoLog += 'VendorErrorCode: ' + dataException.getVendorErrorCode()+'\n';
}
}
}
}
//if returns false or no return, error is not reported to client; if returns true error is reported
//by default error report means logging the error, in smart client an error dialog will also show up
application.output(textoLog);
plugins.file.appendToTXTFile(globals.log,textoLog);
return false;
}
But if the error is handle by try catch sentence, the method onError is executed?
Why a window dialog shows if the return of method is false?
Thank for replys, regards.