Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exception handling of running functions in a dialog
#1
Hello,
Running the function(func3) from the dialog, I have encountered the following problems

about func3:
line 1.
Will pop up an error message,I don't want to pop up an error warning, I need to continue

line 2.
Dialog will lose response, QM quit unexpectedly, dialog crashes

 My Request:
1.When the above three lines of code have an error, run the 5th line code directly.

2.Executing some function through the button in the dialog box, any abnormality in the function will cause the dialog box to close unexpectedly, how to prevent it?

is it possible? Any suggestions are welcome, thanks in advance

Function func3
Code:
Copy      Help
run "abc" ;err ;;Will pop up an error message,I don't want to pop up an error warning, I need to continue
int w=wait(30 WA win("" "Notepad")) ;err ;;Will lose response, QM quit unexpectedly, dialog crashes
act w ;err
;Request: When the above three lines of code have an error, run the 5th line code directly.
MES m.timeout=3; m.style="OCa"; m.default='C'
mes("There are already 3 lines of commands skipped above" "" m)


Macro Macro8
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 88 48 48 14 "func3"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;func3
,func3
ret 1
#2
first off you need to use opt waitmsgn in a dialog if you use any kind of wait function


about func3:
line 1.
Will pop up an error message,I don't want to pop up an error warning, I need to continue

fix
use run flag 0x100 (0x100On error, don't show error message box.)
line 2.
Dialog will lose response, QM quit unexpectedly, dialog crashes

fix
use opt waitmsg 1 before calling func3

 "My Request:"
1.When the above three lines of code have an error, run the 5th line code directly.

see code below with fixes

Function func3
Code:
Copy      Help
int ErrorCount
run "abc" "" "" "" 0x100;err ErrorCount+1
int w=wait(5 WA win("" "Notepad")); err ErrorCount+1
act w; err ErrorCount+1
if(ErrorCount>0) 
,MES m.timeout=3; m.style="OCa"; m.default='C'
,mes(F"There are already {ErrorCount} lines of commands skipped above" "" m)

Macro Macro8
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 88 48 48 14 "func3"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;func3
,opt waitmsg 1
,func3
ret 1

Quote:2.Executing some function through the button in the dialog box, any abnormality in the function will cause the dialog box to close unexpectedly, how to prevent it?
 use err block
Code:
Copy      Help
err-
;your code goes here
err+

this will allow the code to continue on and not end
#3
@Kevin
Thanks for your help, now the code above can run successfully Heart

I still have a question:

If the function func3 includes 100 lines Or more of code, I need to implement:

1.when any line of code error occurs, automatically write the error information and the line number where the code is located to the "$desktop$\err_log.txt" file on the desktop. (I don't want to add error handling after each line of code.)

2.The dialog does not crash or close when any error occurs

is it possible? Can I implement an error handling method similar to C#? eg:   Try ……catch……finally
#4
@Kevin

About use err block:

1.If err+ is added to the end, there is no popup message box at runtime

2.It would be great if add an option to the function err( can log the error message and the line number of the command where the error occurred.), for example:

err-
code
err+ "$desktop$\err_logo.txt"

Function func3
Code:
Copy      Help
err-
run "abc" "" "" "" 0x100
int w=wait(30 WA win("" "Notepad"))
act w
;err+ ;;run ok
MES m.timeout=3; m.style="OCa"; m.default='C'
mes("There are already 3 lines of commands skipped above" "" m)
err+ ;;run not ok
#5
Exception handling is very important in the automated implementation of RPA processes
Add error handling for each line of commands, a little trouble
And, after the error, you need to write the log, and display the error details and the line number in the log.


Forum Jump:


Users browsing this thread: 1 Guest(s)