forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


try, except, end

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Wish List
View previous topic :: View next topic  
Author Message
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1537

PostPosted: Thu Oct 09, 2003 11:27 pm    Post subject: try, except, end Reply with quote

Would like to see a way to capture errors similar to how in Delphi you can do -

try
{execute some code here}
except
{an error has occurred; do something or nothing}
end;


Where you can wrap your code in VDS with a TRY and attempt some code, if any error occurs it jumps to the Except section and runs code if any is there.
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Fri Oct 10, 2003 1:47 am    Post subject: Reply with quote

I am not sure but I think Option errortrap does something similar ?
_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2144
Location: A House

PostPosted: Fri Oct 10, 2003 7:58 am    Post subject: Reply with quote

Yeah, I use the OPTION ERRORTRAP myself.. In there, if I can't anticipate
a possible error, I offer the user the option of trying the operation over
again, or shutting the program down. Though I have had one problem with
that in one program..... The errortrap itself got caught in a perpetual loop
and had to be CTRL+ALT+DEL'd. Sad

-Garrett

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
http://www.freewarehome.com <-- Freeware listings since 1996
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Fri Oct 10, 2003 8:03 am    Post subject: Reply with quote

The biggest headache is once you call option errortrap :
It is not local to a sub/function.
You cannot switch it off either Sad .

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Fri Oct 10, 2003 9:41 am    Post subject: Reply with quote

CodeScript wrote:
You cannot switch it off either Sad .


Yes you can.

Code:
  OPTION ERRORTRAP <blank>


I use this all the time to provide try...except functionality. A true try...except wouldn't be possible in VDS because the language has no structure, any non-sequential of control has to be a command that branches to a label.

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Fri Oct 10, 2003 9:51 am    Post subject: Reply with quote

good tip jules Smile

serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1054
Location: India

PostPosted: Fri Oct 10, 2003 11:07 am    Post subject: Reply with quote

Thanks for the Tip Jules.
_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Vic D'Elfant
Past Contributor
Past Contributor


Joined: 26 Jun 2002
Posts: 673
Location: The Netherlands

PostPosted: Sat Oct 11, 2003 1:17 pm    Post subject: Reply with quote

Something like this would be cool to:
Code:

<?php
$var = 'myvar';
switch($var)
{
  case 'hello'
    print "Hy folks!";
    break;
  case 'myvar'
    print "Hello!";
    break;
}
?>


Vic

_________________
phpBB Development Team
Back to top
View user's profile Send private message Visit poster's website
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Sat Oct 11, 2003 1:30 pm    Post subject: Reply with quote

Again, I achieve this sort of functionality by using a goto %%var with an option errortrap to handle the "else" option of %%var not equalling any label.
_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sat Oct 11, 2003 2:53 pm    Post subject: Reply with quote

Vic wrote:
Something like this would be cool to:
Code:

<?php
$var = 'myvar';
switch($var)
{
  case 'hello'
    print "Hy folks!";
    break;
  case 'myvar'
    print "Hello!";
    break;
}
?>


Vic


Here it is... Smile

Code:
%%var = "myvar"

if @equal(%%var,hello)
  info Hy folks!
elsif @equal(%%var,myvar)
  info Hello!
  end

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Sat Oct 11, 2003 3:11 pm    Post subject: Reply with quote

Here it is as some functions and commands:

Code:
rem --- Include this in your scripts... ---

#define command,switch,break
#define function,switch,case

rem --- Main script ----

%%variable = hello

rem Set the variable which will be 'switched'
switch %%variable

  rem If the switched variable's value is 'hello', do this:
  if @case(hello)
    info "%%variable : hello"
    end

  rem If the switched variable's value is 'hi', do this:
  if @case(hi)
    info "%%variable : hi"
    end
   
  rem With the @switch() function you can get the value of the switched variable...
  info The value of the variable which is switched : @switch()
   
break

exit   
   
rem --- Include this in your scripts... ---

:Switch
  if @unequal(%1,)
    %%CaseValue = @trim(%1)
    else
    exit %%CaseValue
    end
  Exit

:Case
  if @equal(%2,EXACT)
    Exit @equal(%1,%%CaseValue,EXACT)
    else
    Exit @equal(%1,%%CaseValue)
    end

:Break
  %%CaseValue =
  Exit

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group