 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Andi
Joined: 11 Feb 2005 Posts: 173 Location: Germany
|
Posted: Sun Nov 02, 2008 5:10 am Post subject: How to handle the error: call to non-existent function |
|
|
Hello,
I'm looking for a way, catching the error: "call to non-existent function" via errorlevel or something like this.
So when I start the script and ahk comes to the FunctionThatDoesNotExist() I want to avoid stopping the program. Instead it should be possible to react by the program to this error.
Any help would be appreciated!
Best regards,
Andi |
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Sun Nov 02, 2008 2:21 pm Post subject: |
|
|
#ErrorStdOut findest du in der Hilfe. SO einfach ist das.  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Mon Nov 03, 2008 12:39 am Post subject: |
|
|
You can suppress the error by calling the function dynamically:
| Quote: | v1.0.47 released: Stdlib, RegisterCallback, NumGet/Put posted by Chris
Added dynamic function calling. [developed by lexiKos]
Description: A function (even a built-in function) may be called dynamically via percent signs. For example, %Var%(x, "fox") would call the function whose name is contained in Var. Similarly, Func%A_Index%() would call Func1() or Func2(), etc., depending on the current value of A_Index. The called function's definition must exist explicitly in the script, either via #Include or a non-dynamic call to a library containing the function. If the function does not exist -- or if the wrong number or type of parameters is passed to it -- the expression containing the call produces an empty string. |
| Code: | Func=SubStr
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
{
MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
ExitApp
}
Else
MsgBox, % Result
Func=SubString
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
{
MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
ExitApp
}
Else
MsgBox, % Result |
_________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
Andi
Joined: 11 Feb 2005 Posts: 173 Location: Germany
|
Posted: Mon Nov 03, 2008 9:59 pm Post subject: |
|
|
Thank you Bobo and Skan
When I understand it right, the hint from BoBo with #ErrorStdOut stops the script. But I'm searching more for a solution that Skan descibes that keeps the script running. But additional I want to add the missing function to the lib folder.
So I tried the following, but there is one thing I don't understand: When the last but one line is missing, it leads to an error
| Code: | Func=SubStr
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
{
MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
ExitApp
}
Else
MsgBox, % Result
ifNotExist %A_Scriptdir%\lib\subString.ahk
{
ifNotExist %A_Scriptdir%\lib
FileCreateDir, %A_Scriptdir%\lib
FileAppend,
( ;only for testing
Substring(String, StartingPos, Length)
{
return SubStr(String, StartingPos, Length)
}
), %A_Scriptdir%\lib\SubString.ahk
}
Func=SubString
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
{
MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
ExitApp
}
Else
MsgBox, % Result
;The function above:
;Func=SubString
;Result := %Func%( "Skan",1,2 )
;works only, when the following line exists!?
Result := Substring( "Skan",1,2 )
MsgBox, % Result
|
I have to correct me: The first time you run the script, the last but one line stops the script. So when you run the first time without it, you see the error message from the msgbox. But when you run it a second time with the last but one line it doesn't work?!
Last edited by Andi on Tue Nov 04, 2008 4:47 am; edited 1 time in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Mon Nov 03, 2008 11:38 pm Post subject: |
|
|
What you are trying to accomplish is not possible as on date.
AHK reads the whole script before it will execute a single line of it.
You will need two scripts, where the first script will check for dependencies and set things right and then load the target script. |
|
| Back to top |
|
 |
Andi
Joined: 11 Feb 2005 Posts: 173 Location: Germany
|
Posted: Tue Nov 04, 2008 5:00 am Post subject: |
|
|
Thank you Skan for the clarification
I skiped the following sentence | Quote: |
The called function's definition must exist explicitly in the script, either via #Include or a non-dynamic call to a library containing the function. |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|