I'm using RedQueryBuilder to implement a table filter on a web application. When the user clicks an Apply Filter button the current sql and params are sent to a backend application, and the page refreshes. I read in the sql and params back into RQB so it displays the filter applied.
In some cases the user can specify a filter that RQB isn't happy reading back in - for example if they included an empty param for an Integer field. Now I can do some client-side validation as well, but I really want as a first step to be able to recover gracefully if there is a problem. However, the following doesn't actually trap the error:
try {
RedQueryBuilderFactory.create(rq, filter.initial_query, filter.initial_params);
} catch(err) {
//
// There is a problem with the filter. Replace it with default values.
//
filter.initial_query = "SELECT * FROM \"<%=cleanTableName%>\" WHERE (\""+default_column+"\" = ?)";
filter.initial_params = [];
RedQueryBuilderFactory.create(rq, filter.initial_query, filter.initial_params);
//
// Explain the error to the user
//
$("#filter-message").innerText("There was a problem interpreting your filter; this is usually caused by using an empty value or text for filtering a number field. Click Clear Filter to reset the view and try again.")
}
Instead, I'm seeing "Uncaught java.lang.ClassCastException" in the console when the page loads when using a malformed query.
However If I try this in console I do trap an exception as expected.
NB My RQB code above is wrapped in a function executed using Deferred.
Any idea how I can trap these kind of errors?