Archive: Usage of IfError


Usage of IfError
Hello All,

Could anybody let me know the usage of IfErrors with an
example...?
My situation is I've to process for 0 & non-Zero return values
of a function in the .NSI Script. I'd like to use this IfError
command in the .nsi script.
How the same cud b used ?

Thanks In Advance for help.
Regards
Venky


Venky,

eg, when trying to read a file to the end:

loop:
FileRead...
IfErrors -> Exit
Goto loop
Exit:

What is it you want to do exactly???

Good luck, greetz, Hendri.


Henri,

Thanx for your response.

I'm executing "myfile.exe" thru Exec Call with some parameters.

After excuting this I need to compare the Return value of the
function of myfile.exe

The function which generates myfile.exe does return 1 if the function succeeds.

This Return Value of 1 should be checked with IfErrors statement

How can I achieve this?

Thanks In Advance for your help.


Regards
Venky


Hi Venky,

The function which generates myfile.exe does return 1 if the function succeeds.
Is StrCmp or IntCmp what you're looking for???

I use some exe to check a RegCode, maybe this will give you some hint how to do it (because I do not understand what you are doing exactly: a function generates an exe???). See http://forums.winamp.com/showthread....threadid=70530 for RegCode.

Tell me if this solved the problem, good luck,

greetz, Hendri.

Are you trying to do something like this..


ClearErrors ;Make sure there isn't any previous errors.
ExecWait "C:\PathToMy\Program.exe" $0
IntCmp $0 "1" "" goto
;Does something if $0 = 1

goto:
;Comes here if something != 1 you can do other checkcs if you wish


You can also do the Iferrors call to see if an error was defined.. Because in the docs the $0 variable is undefined if you have it and an error occurs.

The IfErrors flag will be set if the exe returns a non-zero value. Zero means that the exe returned sucessfully. You need to use execwait to get the value.

Try:

ExecWait '"$INSTIDIR\myfile.exe"'
IFErrors 0 NoError
;;; Do something here when you have an error
MessageBox MB_OK "ERRORRRRRRRRRRRRRRRRRRR"
Goto EndIt
NoError:
MessageBox MB_OK "GRRRRRRRRRRRRRRRRRRREAT"
EndIt:
;; we're done


Hello All,

Thankx for your replies to the query I've posted.
Henri..sorry I did not elaborate my query.
This is I intended to do.
Execwait "myfile.exe" has been passed with some parameters.
I need to check the return values using IfErros Stmt.
I need to process some command only if the return value is 1.
I could do this by the follg. way
Execwait "myfile.exe" $0
IntCmp $0 "1" "" MyLabel
MessageBox MB_OK "Value is 1";
MyLabel:
SectionEnd.


Hello All,

Thankx for your replies to the query I've posted.
Henri..sorry I did not elaborate my query.
This is I intended to do.
Execwait "myfile.exe" has been passed with some parameters.
I need to check the return values using IfErros Stmt.
I need to process some command only if the return value is 1.
I could do this by the follg. way
Execwait "myfile.exe" $0
IntCmp $0 "1" "" MyLabel
MessageBox MB_OK "Value is 1";
MyLabel:
SectionEnd.

Thanks & Regards
Venky


Hi Venky,

To get the return value, or 'error level' of a program, simply do:

  ExecWait 'MyProgram.exe' $0
$0 will contain the return value.

Hope this helps!
Alex

What the Heck?
The forum system has choked on my response, so:

That's the code. $0 will contain the return value of your program.

Here's the code for my above message. Who knows why it repeats. Incorrectly.

vBulletin is Stuffed.
The forum system has yet again misinterpreted my response. If you type

ExecWait 'MyProg.exe' $0

then $0 will contain the return value of your program.