RobotStudio event

IError not executing trap routine

davidmalott
edited June 2022 in RAPID Programming
I created an interrupt-trap routine with IError to provide details of a particular error. But, the program never enters the trap. Am I missing something? The reason for doing this is to get more granular information on the error similar to the 'event message' which appears of the FP, not simply the ERRNO generated by the error (which is not consistent with the event message number).

VAR intnum err_int;
VAR trapdata err_data;
VAR errdomain err_domain;
VAR num err_number;
VAR errtype err_type;

PROC MAIN()
CONNECT err_int WITH TrapAll;
IError COMMON_ERR, TYPE_ALL, err_int;
.
.
! The line below results in a socket error
SocketConnect sock, host, port;
.
.
ENDPROC

TRAP TrapAll
GetTrapData err_data;
ReadErrData err_data, err_domain, err_type;
.
ENDTRAP


Post edited by davidmalott on

Comments

  • lemster68
    lemster68 ✭✭✭
    What particular error is it that you are trying to identify?  From the manual: It is not possible to order an interrupt on internal errors.
    Lee Justice
  • Hi David, 

    It looks like it's down to not having an error handler in your main routine.
    The trap routine works like any other and won't execute if program execution is halted.

    I believe when an error is raised the controller looks for an error handler and if none is present it will halt execution. If an error handler is present it will continue execution there, but if an appropriate interrupt is registered it will first do the interrupt and then do the error handler.
    I would use the interrupt to save the error information you are looking for to a variable, and then handle the error in an error handler. 

    This example prints the error number recorded from the trap routine in the error handler.

    MODULE MainModule
    	VAR intnum err_int;
    	VAR trapdata err_data;
    	VAR errdomain err_domain;
    	VAR num err_number;
    	VAR errtype err_type;
    	
    	VAR string s_Test;
    	
    	PROC MAIN()
    		
    		VAR socketdev sock;
    		VAR string host := "192.168.123.1";
    		VAR num port:= 9191;
    		
    		CONNECT err_int WITH TrapAll;
    		IError COMMON_ERR, TYPE_ALL, err_int;
    		
    		! The line below results in a socket error
    		SocketCreate sock;
    		SocketConnect sock, host, port, \Time:= 10;
    		
    	ERROR
    		IF err_Domain = PROGRAM_ERR THEN
    			TPErase;
    			TPWrite NumToStr(err_Number,0);
    			TRYNEXT;
    		ELSE	
    			RETRY;
    		ENDIF
    	ENDPROC
    	
    	TRAP TrapAll
    		GetTrapData err_data;
    		ReadErrData err_data, err_domain, err_number, err_type;
    	ENDTRAP
    
    ENDMODULE

    Good Luck, 

    Harry