A list of products available on this site
Documentation for XtraMania's xtras
Prices and links to the online store
Xtras, PDFs, samples
Have a question? Ask us!
Contacts
Logo. www.xtramaina.com  
Home Search E-mail
ActiveCompanion Usage/Common/Errors handling

ActiveCompanionSet xtras for Macromedia Director

Error Handling Support

There are two main levels of errors related to VbScriptXtra. They have completely different nature and therefore have to be handled differently.

Lingo Errors
Lingo errors are similar to incorrect Lingo syntax run-time errors. They cause Director to show error alert saying something like "Method or property not found in object" or "One parameter expected". In Projector they might halt script execution etc. These errors usually mean that something is wrong with the programming. Wrong method call syntax is used or something similar to it. VbScriptXtra might return error codes to Director that make Director to show Lingo error alert box. It happens when wrapper object discovers the programming error at the Lingo level (wrong syntax, wrong parameters and other evident programming errors).

Programming Errors
This level includes errors that are actually exception conditions. They happen or do not happen depending on particular execution context. They are normal in programming practice and have to be handled programmatically. For example if file operation fails it does not have to worry end-user with Lingo error alert box. Instead developer should check whether operation completed successfully and perform what is appropriate.
VbScriptXtra provides programming errors handling support based on storing status of the last call within every wrapper object. In other words, every VbScriptXtra's wrapper object keeps the error code and description returned by the most recently called method or property. Before returning from the call to any wrapper object the last error information (if any) is being set by the wrapper object. Right before calling the next method or property of the wrapper object the last error information is cleared.
To check the status of the most recent call to the object use obj.Failed or obj.Succeeded properties. The error message and error code are available via obj.LastError and obj.LastErrorCode properties.

If Lingo statement includes cascading property access, several wrapper objects might be involved. Most of these wrappers (except the first one) are temporarily and therefore they are not accessible after the Lingo statement. So the error information could be lost. Sometimes it is worth to store intermediate wrappers in a Lingo variable just to have an opportunity to check whether a call was successful.

This sample shows how to check error status when multiple wrappers are involved in cascading property access operation.

on OpenWordDocument strPath
  vb = xtra("VbScriptXtra")
  w = vb.CreateObject( "Word.Application" )
  docs = w.Documents
  doc = docs.Open( strPath )
  if docs.Succeeded then
    return doc
  end if
  alert doc.LastError
  return VOID
end

Compare the above sample to the following one:
on OpenWordDocument strPath
  vb = xtra("VbScriptXtra")
  w = vb.CreateObject( "Word.Application" )
  doc = w.Documents.Open( strPath )
    -- Incorrect check since "w.Documents" always works
    -- while Open( strPath ) might fail
  if w.Succeeded then
    return doc
  end if
  alert doc.LastError
  return VOID
end

Site homeSearchContact author © Eugene Shoustrov. www.xtramania.com