mIRC Home    About    Download    Register    News    Help

Print Thread
#35285 10/07/03 04:11 AM
Joined: Feb 2003
Posts: 309
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
If you know your java or your PHP 5 (yes, go look at the slideshow), you'll have come across the error/exception handling mechanism of try/catch...

For those that don't know, here's a -PSUEDOCODE- example:
alias fakething {
try {
echo -s $ip $nick $ticks
return YAY
} catch (ExceptionType e) {
return ERROR! Something went wrong!
} finally {
echo -s Errors occured!
}
}

What happens is that if for some reason $ip, $nick, or $icks, or even echo -s doesn't work, instead of spitting out * Invalid parameters; blah line blah, it would return "ERROR! Something went wrong!", and execute the code in the finally {} statement.

This is good for situations like working with com objects, where if something goes wrogn in a majro fashion, you want to close the com object down before returning from the alias.
Or with sockets. Or anyhting that blurs the line of robustness (DLL calls...)

you could also customise errors to be handled by aliases, view a /throw command;
ie
try {
echo -s Making an error on purpose!
throw CustomErr $1-
}

alias customerr {
echo -s An error occured with the parameters: $1-
}

Output would be:
Making an error on purpose!
An error occured with the parameters: blah blah

Its possible to do with a tangle of goto loops, but thats just not friendly.

#35286 10/07/03 03:51 PM
Joined: May 2003
Posts: 22
A
Ameglian cow
Offline
Ameglian cow
A
Joined: May 2003
Posts: 22
hmm... not that bad ... I whould use it ..


--------------------------------------------------
I really don't know anything.... I just fake it
#35287 10/07/03 04:55 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Heh I love this. I posted this a while ago and got responses like "mIRC isn't C++" "mIRC isn't OOP" etc. Now when you post it you get "thats the greatest idea anyone ever proposed!!!"

But anyway, there is a flaw with your design there, "ExceptionType" mIRC has no concept of types, it is not a type based language. I think adding a type system solely for use in exceptions would be a bad thing.

#35288 10/07/03 05:16 PM
Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
It was probably me :tongue: and if so, I wasn't necessarily objecting to it, I would have just stated that I had no use at all for such a thing. I forget what was said in the posts though I do know one thing, I might have objected to mIRC's scripting language undergoing huge changes to accomodate what you just mentioned would not be possible.

#35289 11/07/03 06:30 AM
Joined: Feb 2003
Posts: 309
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
Ah but here's where we use our wildcards to match the errors;
wheter its invalid syntax or missing parameters or no such command, or WHATEVER...

try {

} catch (*) {
/globErrHandler $1-
}

try {

} catch (*syntax*) {
/synErrHandler $1-
}


#35290 11/07/03 03:10 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Yes I'm just saying all exceptions should be "strings" they shouldn't be InvalidParamType or something to that affect.

#35291 13/07/03 02:42 AM
Joined: Jul 2003
Posts: 14
R
Pikka bird
Offline
Pikka bird
R
Joined: Jul 2003
Posts: 14
hey man, this is an awesome suggestion and i would love to see it in there. I program in Visual Basic .NET and it uses this and it is a saviour in many situations.


Link Copied to Clipboard