Monthly Archives: January 2012

UMRA Clean Error Handling

Today I will show you how to structure clean error handling in Tools4ever UMRA project. Assumption is you have basic understanding of UMRA visual scripting and built-in error handling capabilities.

Let’s start off with a basic project skeleton where we’ll simply read some users:

Note the following:

  • “Error” handler at the bottom that will execute “Handle Error” project
  • “On error” jumps on the first two actions
  • Second “On error” jump is an actual “Execute script ‘Get Users'” action – any UMRA errors occurring inside that script will cause this jump to trigger; in other words, UMRA errors at any level of the stack will propagate up

This is where it gets interesting.  Inside of our “Get Users” script we will read some data into %TB_Users%, using “Generate Generic Table” action.  In case this action fails (i.e. LDAP domain controller in unavailable or database authentication failed), UMRA will properly execute and propagate an error. However, what if we need to have an error based on a logic condition, i.e. if user data contains no records (shown below), or number of records falls outside the expected range?

In the past, to handle “logic” errors, I would do something like Set Variable %Error% in the called project, then check for the presence/value of that variable in the calling project.  While this worked, I wasn’t leveraging UMRA’s native capabilities, and I ended up having multiple additional lines of code, at various levels of the stack, to accommodate this approach. This reduced readability of my projects.  I give to you, my new approach; here’s the Get Users project:

…note:

  • The very first action – Generate generic table – jumps straight to the end of file (EOF); this is because any “native” UMRA errors such as this one will propagate properly
  • The third line is our “logical” error – if there are no records in the table, we want to error out, so we ultimately jump down to “Error: Row Count”, where we will execute project “Throw Error”, which will give us a “native” UMRA error

Finally, here’s the “Throw Error” project, which allows us to propagate a native UMRA error; I know it’s a hack, but it works: