PDA

View Full Version : [InstallScript] Handling exceptions (try, catch, endcatch)



google44
06-20-2006, 07:43 AM
I use the following code for catch exceptions in InstallScript project (example):

Dlg_SQLServerSelectLogin:
try
nResult = OnGetSQLServer( sqlsrv,sqlusr,sqlpas,sqlbul);
catch
MessageBox(Err.Description , SEVERE);
endcatch;
if (nResult = BACK) goto Dlg_CustomDialog4;

The problem is that if and unhandled exception occurs (function crashes or something) the MessageBox shows no description of the error, just a blank MessageBox.
Example:
without try, catch, endcatch error is when i hit browse on sql server dialog:

http://img210.imageshack.us/my.php?image=error2zq.jpg

and when i put try, catch, endcatch a MessageBox with no description is displayed

How can i display the exact message as in screenshot when i put try, catch and endcatch ?
Thank you

sciglione
03-18-2008, 07:27 AM
I know that Google44 probably alredy solved this problem, but I got into the same situation and fried my head off to resolve it. So, I Will share my solution.

I don't know why, but if you do not catch the especific error that installshield throws you can't show the Err.Description (that's why the blank MessageBox), so we need to catch the exception by its number, like this:

nTemp = Err.Number;
switch (nTemp)
case 0x80040707:
MessageBox("DLL function call crashes...", WARNING);
default:
MessageBox(Err.Description , SEVERE);
abort;
endswitch;

I hope this will help somebody in the future.

[]'s,

Sérgio