ImageGear Professional for Windows ActiveX
Working with Error Handling

When an error condition is detected during call to any ImageGear property/method, an error code and all necessary error information is placed in an internal memory area called the ImageGear error stack. You can analyze the error stack for the error count and error information.

The error stack information is available via an object IGResult Object that is belongs to the Core type library.

Information about any error is available via IGResultRecord Object.

IGResult Object has the following properties and methods:

Name Prop/Method Description
IsOK Property Method Returns True if there is no errors, False otherwise.
ErrorCount Property Prop, Get Returns a count of error on the error stack (count of records of the level 0).
NotificationFlags Property Prop, Get/Put Specifies a method to inform the customer about an error. See examples below.
RecordCount Property Prop, Get Returns a count of records of the specified level on the error stack.
RecordsTotal Property Prop, Get Returns a total count of the records on the error stack.
GetError Method Method Returns IGResultRecord Object describing the specified error.
GetRecordWithLevel Method Method Returns IGResultRecord Object describing the specified record of the specified level.
Clear Method Method Clears all records on the error stack.

The NotificationFlags Property allows to choose a way how the customer will be informed about an error. It can take the following values:

IG_ERR_NO_ACTION No action in case of error. The customer should analyze an error stack after call to the any property/methods. See Example 1. No Action when Error Occurs.
IG_ERR_OLE_ERROR An OLE container is informed about an error via IErrorInfo interface. See Example 2. OLE Error.
IG_ERR_EVENT_ERROR ImageGear will fire IGError Event event every time the error (record of level 0) is added to the error stack. Information about the error is located in the ResRec parameter. See Example 3. Error Events.
IG_ERR_EVENT_WARNING ImageGear will fire IGError Event event every time the warning (record of level 1) is added to the error stack. Information about the warning is located in the ResRec parameter. See Example 3. Error Events.

Below is a brief description of properties of IGResultRecord Object:

Name Description
FileName Property The name of the file where an error/warning has been set.
LineNumber Property The number of the line.
ErrCode Property The code of the error.
Level Property The level of the record. 0 - error, 1- warning.
Value1 Property First attribute of the error/warning.
Value2 Property Second attribute of the error/warning.
ExtraText Property Extra text string describing an error.

Example 1. No Action when Error Occurs

 
Copy Code
Public page as IGPage
` Set notification flags to IG_ERR_NO_ACTION
IGCoreCtl1.Result.NotificationFlags = IG_ERR_NO_ACTION
`Create a page and load an image
Set page = IGCoreCtl1.CreatePage
IGFormatsCtl1.LoadPageFromFile page, "myimage.jpg", 0
`check for error
if not IGCoreCtl1.Result.IsOk() then
`Get error count
Dim errcount as Long
errount = IGCoreCtl1.Result.ErrorCount
`Get error description
Dim rec as IGResultRecord
Set rec = IGCoreCtl1.Result.GetError(errount - 1)
`Get error code 
Dim errcode as enumIGErrorCodes
Errcode = rec.ErrCode
`Some error processing
...
`Clear error stack
IGCoreCtl1.Result.Clear
End if

Example 2. OLE Error

 
Copy Code
Dim errorRecord As IGResultRecord
Dim i As Integer
On Error GoTo ErrorHandler
IGCoreCtl1.Result.NotificationFlags = IG_ERR_OLE_ERROR
Set page = IGCoreCtl1.CreatePage
IGFormatsCtl1.LoadPageFromFile page, "myimage.jpg", 0 
Exit Sub
ErrorHandler:
If IGCoreCtl1.Result.IsOk() then
   `Internal COM error
    MsgBox "VB returned an error (" + Hex(Err.Number) + "):" +
vbCrLf +
Err.Description, vbExclamation, "Internal COM Error" 
Else
  `IG error
   For i = 0 To IGCoreCtl1.Result.RecordsTotal - 1
   Set errorRecord = IGCoreCtl1.Result.GetRecord(i)
   MsgBox "ImageGear returned an error (" + errorRecord.ErrCode
+ "):" +
vbCrLf + errorRecord.ExtraText, vbExclamation, "ImageGear
Error" 
   Next i
End If
Exit Sub

Example 3. Error Events

 
Copy Code
Public page as IGPage
` Set notification flags to IG_ERR_EVENT_ERROR or
IG_ERR_EVENT_WARNING
IGCoreCtl1.Result.NotificationFlags = IG_ERR_EVENT_ERROR or
IG_ERR_EVENT_WARNING
`Create a page and load an image
Set page = IGCoreCtl1.CreatePage
IGFormatsCtl1.LoadPageFromFile page, "myimage.jpg", 0
Exit Sub
` error processing
Private Sub IGCoreCtl1_IGError(ByVal ResRec As
GearCORELibCtl.IIGResultRecord)
MsgBox "Event: " & ResRec.ExtraText
End Sub

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback