mIRC Home    About    Download    Register    News    Help

Print Thread
#42439 17/08/03 03:30 PM
Joined: Feb 2003
Posts: 7
E
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
E
Joined: Feb 2003
Posts: 7
It would be nice if mirc allowed to catch errors within a script, to prevent the script from halting.

How about an "on exception" event or something like this, which gives the $errormsg (like "line too long"), the $errorscript (name of the script in which the error occured) as well as the $errorline (line number in the script).

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
You can try the script posted at this thread for now, it uses Singals to trap errors... a very nifty use if I say so.

However I agree, built in error-trapping could be handy.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 43
P
Ameglian cow
Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 43
to catch an error you can use a dll with the SendMessage command. To keep a script from halting you could use "$dde($ddename,Evaluate,$identifier)" and "//dde $ddename Command "" //command". Both methods have problems, but it is a short term solution.
I beleive it would be a good idea to have something like a $catch identifier so that you can use $catch(<alias>,[N]), you would fill <alias> with a command or identifier, and [N] with a switch "C" for command, and "I" for identifier. It would return either "SUCCESS [ReturnText]" or "ERROR [ErrorText]. "on *:ERROR:<alias>:<commands>" would be nice as well.
I know this is not the best solution, and I am sure someone will come up with something better.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
The Signal script I mentioned above is quite nice, and faster than sending DLL calls. Give it a go.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 43
P
Ameglian cow
Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 43
using dll calls is just as fast
here is copy of dll code from main asm file, there are a couple other files needed, but it is just a .inc file, .dec file, and the copytext functions
mrcdll.asm:
Code:
.386
.model flat, stdcall
option casemap :none
include	mrcdll.inc
.data
szReturnError	db	"ERROR %1!s!%0",NULL
szReturnSuccess	db	"SUCCESS %1!s!%0",NULL
szMirc		db	"mIRC",NULL
.data?
hInstance	dd	?
hFileMap	dd	?
mData		dd	?
mArgs		dd	3	dup	(?)
.code
LibMain		proc	hInstDLL:DWORD,reason:DWORD,unused:DWORD
	.if reason == DLL_PROCESS_ATTACH
		mov	eax,TRUE
		ret
	.endif
	mov	eax,TRUE
	ret
LibMain	Endp
LoadDll		proc	LoadInfo:PTR LOADINFO
	push	ebx

	invoke	CreateFileMapping,	INVALID_HANDLE_VALUE,0,PAGE_READWRITE,0,4000h,offset szMirc
	mov	hFileMap,eax
	
	invoke	MapViewOfFile,		hFileMap,FILE_MAP_ALL_ACCESS,0,0,0
	mov	mData,eax

	IF	UNLOAD
		mov	ebx,LoadInfo
		mov	[ebx].LOADINFO.mKeep,FALSE
	ENDIF
	invoke	GetModuleHandle,	NULL
	mov	hInstance,eax
	pop	ebx
	ret
LoadDll		endp
UnLoadDll	proc	mTimeout:dword

	IF	KEEPLOADED
		.if	mTimeout==1
			mov	eax,0
			ret
		.else
			invoke	UnmapViewOfFile,	mData
			invoke	CloseHandle,		hFileMap
			mov	eax,1
			ret
		.endif
	ELSE
		invoke	UnmapViewOfFile,	mData
		invoke	CloseHandle,		hFileMap
		mov	eax,1
		ret
	ENDIF
UnLoadDll	endp
DoIdentifier	proc	mWnd:dword,aWnd:dword,data:dword,
			parms:dword,show:dword,nopause:dword
	invoke	CopyText,		mData,data
	invoke	SendMessage,		mWnd, WM_MEVALUATE,0,0
	m2m	mArgs,mData
	.if	eax
		invoke	FormatMessage,	FORMAT_MESSAGE_FROM_STRING or FORMAT_MESSAGE_ARGUMENT_ARRAY,
					offset szReturnSuccess,NULL,NULL,data,950,offset mArgs
	.else
		invoke	FormatMessage,	FORMAT_MESSAGE_FROM_STRING or FORMAT_MESSAGE_ARGUMENT_ARRAY,
					offset szReturnError,NULL,NULL,data,950,offset mArgs
		;invoke	CopyText,	data,offset szReturnError
	.endif
	mov	eax,3
	ret
DoIdentifier	endp
DoCommand	proc	mWnd:dword,aWnd:dword,data:dword,
			parms:dword,show:dword,nopause:dword
	invoke	CopyText,		mData,data
	invoke	SendMessage,		mWnd, WM_MCOMMAND,1,0
	m2m	mArgs,mData
	.if	eax
		invoke	FormatMessage,	FORMAT_MESSAGE_FROM_STRING or FORMAT_MESSAGE_ARGUMENT_ARRAY,
					offset szReturnSuccess,NULL,NULL,data,950,offset mArgs
	.else
		invoke	FormatMessage,	FORMAT_MESSAGE_FROM_STRING or FORMAT_MESSAGE_ARGUMENT_ARRAY,
					offset szReturnError,NULL,NULL,data,950,offset mArgs
	.endif
	mov	eax,3
	ret
DoCommand	endp
end LibMain

Joined: Dec 2002
Posts: 196
T
Vogon poet
Offline
Vogon poet
T
Joined: Dec 2002
Posts: 196
And possibly also detect and stop unlimited loops from occuring, and show an error. sometimes I forget adding in the inc :tongue:


trenzterra
AustNet #trenzterra and #w
Head Scripter @ http://trenzterra.uni.cc
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
How about "unreachable code" or "Variable N is never used" >:F


-KingTomato

Link Copied to Clipboard