Jump to content

Function Try Except (Delphi)


 Share

Recommended Posts

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

Link to comment
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.
Link to comment
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

Link to comment
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)

Link to comment
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
Link to comment
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

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...