Old 25th January 2007, 19:57   #1
drod
Junior Member
 
Join Date: Jan 2007
Location: UK
Posts: 9
Error Code detection

Hi,

I'm trying to capture any errors my applications may come across, but after searching the forums etc I'm still can't see an explanation.

I can see an error if I do something like:

ClearErrors
<try to create file x>
${If} ${Errors}
DetailPrint "Error creating file x"
${EndIf}

It seems like I can only get an "errorFlag" raised and that I have to know the context of the error; i.e I was trying to create "file x" and it failed.

I'd like to do something like:

ClearErrors
<try to create file x>
<try to create file y>
<try to create file z>
${If} ${Errors}
DetailPrint "Error creating file <name of file>"
${EndIf}

...but I think I may have to write:

ClearErrors
<try to create file x>
${If} ${Errors}
DetailPrint "Error creating file x
${EndIf}
ClearErrors
<try to create file y>
${If} ${Errors}
DetailPrint "Error creating file y"
${EndIf}
ClearErrors
<try to create file z>
${If} ${Errors}
DetailPrint "Error creating file z"
${EndIf}

Is this correct, or am I missing something? Thanks.
drod is offline   Reply With Quote
Old 25th January 2007, 20:09   #2
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
It's mandatory to ClearErrors just before you're going to perform an action that might set the error flag.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 25th January 2007, 20:12   #3
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
You can wrap it in a macro for easier coding.
code:
!macro FileWithTest file
ClearErrors
File "${file}"
${If} ${Errors}
DetailPrint "error with ${file}"
${EndIf}
!macroend


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 25th January 2007, 20:47   #4
drod
Junior Member
 
Join Date: Jan 2007
Location: UK
Posts: 9
Thanks guys. I'd realised I could wrap checks into macros, but I thought there may be a way to be more intelligent by say checking errors status codes returned by each command.

It just seems that it could make the code very bulky if I have to check the status of most of the commands I run.
drod is offline   Reply With Quote
Old 25th January 2007, 21:31   #5
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
Quote:
Thanks guys. I'd realised I could wrap checks into macros, but I thought there may be a way to be more intelligent by say checking errors status codes returned by each command.
So where is the difference if instead of:
ClearErrors
File <try to create file x>
IfErrors do_this do_that

you were using:
File <try to create file x> $0 ;return var
StrCmp $0 "<errorlevel> do_this do_that

It doesn't seem a difference to me

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Old 25th January 2007, 22:21   #6
drod
Junior Member
 
Join Date: Jan 2007
Location: UK
Posts: 9
Sorry red wine, I don't think I've explained myself well enough at all!

If I was writing a Unix script I'd be able to access the return code in the "$?" variable - this may be say "2" for "no such file", or "13" for "permission denied" etc. You could pass that info back to the user so they knew the cause of the error.

Unless I'm missing it, I only seem to be able to get a "you had an error" here. I think this means that I have to wrap each call with a "clearErrors/IfError" type block in order to offer a little more info; eg

ClearErrors
<open file for writing>
${If} ${Errors}
DetailPrint "Cannot open file for writing"
${Else}
ClearErrors
<try to write>
${If} ${Errors}
DetailPrint "Cannot write to file"
${Endif}
${Endif}

Does that make sense?
drod is offline   Reply With Quote
Old 25th January 2007, 23:09   #7
Red Wine
Forum King
 
Red Wine's Avatar
 
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
You're right I guess. I misunderstood.
I thought we're talking about file extraction, indeed regarding to file extraction doesn't make any noticeable difference.

Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS
Red Wine is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump