Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Try/Catch to subclassed Exception type?
Message
De
09/06/2005 07:14:22
 
 
À
09/06/2005 05:15:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01021735
Message ID:
01021744
Vues:
23
>Is it possible to specify an exception subclass for the Exception objects created by CATCH TO statement?
>
>In other words:
>
>
>local myException as myExceptionClass
>
>try
>  code here ...
>
>catch to myException as myExceptionClass
>  error handling code
>
>endtry
>
>
>Or (as I suspect), CATCH TO only creates objects of the base Exception class?
>

Yes.
Why? Because this open the myExceptionClass instantiation issue.

If myExceptionClass fire a nested error, the C++ routine go out of manage.

A solution is this:
myException=CREATEOB("myExceptionClass")
try
  code here ...

catch to myException ADDITIVE && if myException is a Exception, 
                              && VFP fill it with this context error values, no VFP code run  
                              && at the end, VFP can call a catch event 
endtry
BUT with this restriction: no VFP code run during the filling (not _Assign executed )


>If so, is there any scenario wher eit makes sense to subclass the base Exception class?
>

OOP elegance and speed.
Exception is the VFP baseclass with methods faster to being created.
then:
- Capture the error into a exceptionvar
- use a specific exception class to manage the exceptionvar.

>Thanks,
>Malcolm
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform