|
|
#1 |
|
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. |
|
|
|
|
|
#2 |
|
Forum King
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 |
|
|
|
|
|
#3 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
You can wrap it in a macro for easier coding.
code: NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#4 |
|
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. |
|
|
|
|
|
#5 | |
|
Forum King
Join Date: Mar 2006
Location: Ath. GR
Posts: 2,078
|
Quote:
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 |
|
|
|
|
|
|
#6 |
|
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? |
|
|
|
|
|
#7 |
|
Forum King
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 |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|