« Trip booked for Birmi… | Home | Real Studio meeting i… »

Handling errors is important!

Error handling is very important in every application development. Things go wrong. You can't write a file as you don't have permissions, disk is full or the file exists already and is protected, maybe by some app having it open. The connection to a server or database may be lost or some object property may have been set to nil somewhere else in your code.

Still I see a lot of code from users where functions returning error status are called with the call statement. Or I see exceptions not being handled as well as function results not being verified if they are nil. There are some common error cases which developers like to forget:
  • new picture raises exception for out of bounds (negative size!) or out of memory situations.
  • folderitem.item() returns nil on missing permissions.
  • SQLSelect returns nil recordset with SQL Syntax errors
  • Picture.Open can raise an exception
  • getting a value from a dictionary can raise a TypeMistmatchException, like for converting a window to a string.
There are still a lot of functions which silently fail without an error notice. And we have plenty of them in the plugins. So over the last month we got a couple of more checks in the plugin. Hundreds of functions have been modified to raise an exception if parameters are nil or required text parameters are empty strings. For example TiffPictureMBS.Open now raises NilObjectException with message "folderitem is nil" if you pass nil for the file parameter. So be sure you check the message and fix the problem. There is even a feedback report to have the IDE display the message of an exception (case 22193: Show Exception message in debugger)

Unfortunately we had a bug in adding the exception checks. DynaPDFMBS.CreateNewPDF is okay with passing nil for the folderitem. You do that in order to create a PDF file in memory. The 12.5pr1 DynaPDF plugin raises an exception as I added an unnecessary nil check there. You'll find an updated plugin in the Prerelease download folder to fix this. The biggest plugin in space...
09 10 12 - 23:25