Sign in to follow this  
Followers 0
macost

Function Try Except (Delphi)

8 posts in this topic

Dear all,

I´m needing to use the function "Try Except" because I don´t want to stop my program if a error occurs. But i didn´t find this function in the Help, Forum... anyone knows something about it?

Thanks in advanced.

Maycon Costa

Share this post


Link to post
Share on other sites



Wrong forum.

What does the Try Except do? Is it an error catching clause? If you are using AutoIt, catch errors by checking the @error value. If you are using Delphi with AutoItX, I really have no idea what you are asking.

Share this post


Link to post
Share on other sites

Dear all,

I´m needing to use the function "Try Except" because I don´t want to stop my program if a error occurs. But i didn´t find this function in the Help, Forum... anyone knows something about it?

Thanks in advanced.

Maycon Costa

I use Try/Except in Delphi but have never missed it in AutoIt. Can you give an example of where you think you would need it in an AutoIt script?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hello,

I´m looking for a similar function of Try Except in AutoIT. Here´s a sample of the code (Delphi):

try
    WinExec('c:\program.exe');
except
      ShowMessage(' ERROR' );
end;

I need to use one cod equal in Auto It.

tks

Share this post


Link to post
Share on other sites

Hello,

I´m looking for a similar function of Try Except in AutoIT. Here´s a sample of the code (Delphi):

try
     WinExec('c:\program.exe');
 except
       ShowMessage(' ERROR' );
 end;

I need to use one cod equal in Auto It.

tks

Do something like

$string = Run(...)

If $string = ... Then

....

Else

; do something else

EndIf


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Note: _GetLastErrorMessage is not neccessary just for exact error message

Opt("RunErrorsFatal", 0)
Run('calc2.exe')
If @error Then MsgBox(16, "Error", "Run() produced and error:" & @CRLF & _GetLastErrorMessage ())

Func _GetLastErrorMessage($DisplayMsgBox="")
    Local $ret,$s
    Local $p    = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM        = 0x00001000

    If @error Then Return ""

    $ret    = DllCall("Kernel32.dll","int","GetLastError")

    $ret    = DllCall("kernel32.dll","int","FormatMessage", _
                        "int",$FORMAT_MESSAGE_FROM_SYSTEM, _
                        "ptr",0, _
                        "int",$ret[0], _
                        "int",0, _
                        "ptr",DllStructGetPtr($p), _
                        "int",4096, _
                        "ptr",0)
    $s    = DllStructGetData($p,1)
    $p = 0
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s
EndFunc

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Note: _GetLastErrorMessage is not neccessary just for exact error message

Opt("RunErrorsFatal", 0)
Run('calc2.exe')
If @error Then MsgBox(16, "Error", "Run() produced and error:" & @CRLF & _GetLastErrorMessage ())

Func _GetLastErrorMessage($DisplayMsgBox="")
    Local $ret,$s
    Local $p    = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM        = 0x00001000

    If @error Then Return ""

    $ret    = DllCall("Kernel32.dll","int","GetLastError")

    $ret    = DllCall("kernel32.dll","int","FormatMessage", _
                        "int",$FORMAT_MESSAGE_FROM_SYSTEM, _
                        "ptr",0, _
                        "int",$ret[0], _
                        "int",0, _
                        "ptr",DllStructGetPtr($p), _
                        "int",4096, _
                        "ptr",0)
    $s    = DllStructGetData($p,1)
    $p = 0
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s
EndFunc

Happy birthday Zedna :)

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0