Food for thought (was: Re: jsp vs php)
Yannis Kotsinos
zookie at med.auth.gr
Mon Oct 22 17:36:01 EEST 2001
Giorgos Keramidas <charon at labs.gr> says:
(ouf brhka epiteloys wra na apanthsw...)
loipon:
try {
>Ekei pali exeis problhmata pou o programmatisths prepei na exei
>'peira' gia na ta xeiristei omws, afou akomh den jero an kwdikas pou
>kanei panw apo ena pragmata pou exoun kapoiou eidous dependency to ena
>apo thn epituxia / apotuxia tou allou, prepei na grafetai etsi:
>
> try {
> DoThis();
> } catch (Exception e) {
> // handle exceptions for DoThis();
> }
>
> try {
> DoThat();
> } catch (Exception e) {
> // handle exceptions for DoThat();
> }
>
>h etsi:
>
> try {
> DoThis();
> DoThat();
> } catch (Exception e) {
> // handle all exceptions for DoThis() and DoThat()
> }
Egw protimaw kati analogo me to e3hs:
Pera apo to package poy 8a periexei to en logw app, servlet, whatever,
exeis ena helper object me private variables poy kaneis popoulate me
setters.
ie. estw se ena pi8ano block (sto opoio mporoyn na xrhsimopoih8oyn
diaforetika catches gia diaforetika exceptions parepiptwntos):
try {
DoThis();
DoThat()
}
catch (DoThisException doThis) {
doThis.printStackTrace();
// kai edw xrhsimopoiw toys analogoys setters
helper.setNoError(0);
// To reference se ti xtyphse
helper.setErrorCode(33);
// Synexizoyme?
helper.setSeverity(1);
// kai ie, analoga me to severity unomment
return myObject;
}
catch (DoThatException doThat) {
doThat.printStackTrace();
helper.setNoError(0);
helper.setErrorCode(23);
helper.setSeverity(0);
// return myObject;
}
Etsi mporeis na apomwnwseis toso to error alla kai na apofasiseis gia
to an 8a synexistei to execution h oxi (gi' ayto poy eleges parakatw).
h an den 8eleis return (see bellow), mporeis na elegxeis ena geniko
error opws:
if (helper.getNoError() == 0) {
// continue other code
}
Opote mporei na mhn glitwseis ena if extra, alla sigoyra den 8a exeis
kai toso poly horizontal scrolling. Fysika, an 8eleis na glitwseis to
if mporeis panta na kaneis return, an kai kapoios palios moy eixe pei
oti einai asxhmo programming na kaneis return panw apo mia fora :-)
Pantws edw mporeis na exeis getters kai setters gia polla diaforetika
errors. px. authError, serverError, userError, nonSevereError (mpliah)
kai paei legontas, alla kai na ta omadopoihseis se try {} catches {}
analoga me to severity poy 8ewreis oti exoyn.
>H gia na kano ta pragmata akoma pio asxhma, se ena call tree opws to
>parakatw ...
>
> main
> +-- DoThis
> | `-- DoThat
> +-- DoSomething
> `-- DoSomethingElse
> `-- DoEvenMore
>
>... an ena exception energopoih8ei sto DoThat() h sto DoEvenMore()
>poios tha to xeiristei auto to exception?
>
>Ki an h main() den xeiristei kapoio exception mias apo tis functions
>pou klh8hkan kai auto to exception pernwntas olo kai pio pshla sto
>call-stack tou programmatos ftasei sthn main() alla telika fanei oti
>den exei kapoio handler autou tou exception h main(), ti ginetai?
>Kremaei olo to programma, kai petaei to gnosto mas core dump, h oxi?
ap' oso 3erw (kai an se exw katalabei kala edw) an mia me8odos soy oso
deeply nested kai an einai petaei kapoio exception poy esy den
pianeis, tote 8a se stamathsei o idios o compiler me error.
Alla akoma kai an 8ewrhsoyme oti 8a mporoyse na ginei kati tetoio,
mporeis na kaneis ta akoloy8a:
- Eite na pros8eseis ena generic (Exception e) poy 8a piasei
opoiodhpote allo exception (se periptwsh specific e's ennoeitai)
- na pai3eis me to legomeno finally block.
- Telos na baleis OLO twn kwdika se ena try, catch, kai na pianeis ena
exception e (koinws na toy peta3eis to holy hand grenade !!!!) :-)
> Tote ftaiei o programmatisths
>pou den sxediase kala to programma tou? Kai auto poso diaforetiko
>einai apo thn eu8unh pou exei enas programmatisths na koitazei ola ta
>return values se mia procedural non-object-oriented glwssa (opws h C
>gia paradeigma)?
fysika kai ola katalhgoyn ston programmatisth :-) Alla me mia OO
glwssa exeis arketa yper. eidika an milame gia ena team kai oxi mono
enan programmatisth.
nomizw katalabaineis poy to paw (interfaces, interfaces) ;-)
>-giorgos
}
catch (Exception e) {
e.phew();
Mutt.out.println ("I enjoy talking with you :-)");
}
--
"Our generation has had no Great
Depression, no Great War. Our war is
spiritual. Our depression is our lives."
More information about the Linux-greek-users
mailing list