Re: Error handling in 4gl.
Posted in 1998
Gabbard, Mike W. wrote: > > With new coming dawn of Dynamic-4gl, we are in the need of handling error > messages and displaying them back to users. I was wondering if anyone out > there has a error handling function that they might be willing to share. I > can handle all the display of the messages just fine, just looking for a way > of group error messages. Different types of error messages will require > different type of action for the program > > Mike Gabbard > Red Man Pipe & Supply Company I'm not sure exactly how you want to type your errors, but the general design I use might be a start: function myfunc() whenever error goto l_catch ... call my_other_function() if (sqlca.sqlcode < 0) then goto l_catch end if ... if ok then call commit_work("Saved your work") end if ... whenever error continue -- required for some versions of 4GL label l_catch: call catch_errors("Work not saved") end function function catch_errors(msg) define msg char(80) define stored_sqlcode smallint whenever error continue if (sqlca.sqlcode < 0 and sqlca.sqlcode != NOTFOUND) then let stored_sqlcode = sqlca.sqlcode call error_msg("", msg) call message_saveonly(msg) -- cheat a bit and rollback after the message -- improves response and avoids rollback clobbering sqlca.sqlcode rollback work call begin_work() let sqlca.sqlcode = stored_sqlcode end if end function Notes: function catch_errors() just ignores non-errors. function error_msg() pops up a dialog box with the error followed by msg. It does a little translation of the commoner messages to help the user understand what to do next. function message_saveonly() saves the message in a status bar list the user can use to examine the last 12 messages that flashed past. function begin_work() immediately begins work after a rollback (or commit) if in a non-ANSI database. This makes ANSI and non-ANSI databases behave in the same way. -- Peter Lancashire Information Systems Specialist, Bayer plc Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK Tel: +44-1635-562258, Fax: +44-1635-562281 --- If all else fails, read the instructions and the release notes. Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/ ---