Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Global handling of try/catch error message

Avatar

Former Community Member
For the ease of debugging and centralizing error handling I would like to have a global function that takes care of reporting catched errors. All catched errors are in one and the same global script library, but if I try to centralize the error handling, I don't get any error message at all. The idea is to call a special error reporting function from all the try-catch statements in the library but either it isn't working or I've missed something.

The error variable in catch(error) is also made global so that it would be possible for the different functions to access it.



Example, nevermind no error would be thrown here:

function checkWeather()

{

try{

if(temperature > "25c")

var hot = true;

}

catch(error)

{

handleCatchedError();

}

}



handleCatchedError()

{

xfa.host.messageBox(error); //No error reported??

}

var error = "";



Any thoughts of a solution?
3 Replies

Avatar

Level 7
I would guess your scope for the "error" variable is limited to the the field in which it was caught. Try passing the "error" variable to the "handleCatchedError(error)" and updating that function to handle the variable:



handleCatchedError(oError)

{

xfa.host.messageBox(oError); //No error reported??

}

return;

}



You also might want to look at the Error object introduced with version 6 and updated in version 7.



try {

app.alert(); // one argument is required for alert

} catch(e) {

for (var i in e)

console.println( i + ": " + e[i])

}

Avatar

Former Community Member
The first suggestion is already tried without any luck. Actually that was my first choice, but when that didn't work I tried making the error variable global. But there might be a point in your guess about the error scope, since I don't want the script functions in the fields but in a global script object that might very well be the reason why it isn't working. That would be a huge drawback but they'll probably fix it for version 10 or so of the designer...



I'll also take a look at your other suggestion about the error object and see if that would bring me closer to success.

Avatar

Former Community Member
Problem solved. It turned out to be that it isn't possible to only print the error, it has to be some more text for some strange reason...

messageBox(err); //Not working

messageBox("Error: " + err); //Working...



Thanks for the input, don't we all just love the way the Designer helps us in our efforts to make nice work ;)