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.
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.