Exception : an ugly grammer in programming
- From: Yarco <yarco.w@xxxxxxxxx>
- Date: Tue, 17 Jul 2007 03:03:36 -0700
Well, friend. Yes, I'm doing PHP. But exception is a traditional
machinism in programming languages. I'm very doubt about this.
In procedure language, we return error code when we meet an error. So
we need to design error code table and judge them in several
statements. Finally they become boring.
But how about use exception in OOP? Did we drop all "return error
code" styles?
If i want to fetch a webpage:
<?php
function fetchPage($url)
{
//...do something
//if the net speed is very slow, cause we can't fetch the page
throw new SlowNetSpeed("page can't be getted");
//if the page is moved
throw new NoPage("page does't exist");
//...do something
}
// so what can i do, if i want the fetchPage procedure go on fetching
when SlowNetSpeed Exception happen?
// it stop when NoPage Exception happen?
while (1)
{
try
{
$c = fetchPage('Some_Where');
// do something
break;
}
catch (SlowNetSpeed $e)
{
}
catch(NoPage $e)
{
break;
}
}
?>
It is very ugly if there exists more Exceptions and other procedure.
Then i'm missing "return error code" style. But i know "return error
code" is not a good method when we deal with error. And exception is
also an ugly grammer when we want to keep code clean.
.
- Follow-Ups:
- Re: Exception : an ugly grammer in programming
- From: Joe Scylla
- Re: Exception : an ugly grammer in programming
- From: Jerry Stuckle
- Re: Exception : an ugly grammer in programming
- From: Mindaugas.Liubinas@xxxxxxxxx
- Re: Exception : an ugly grammer in programming
- From: Willem Bogaerts
- Re: Exception : an ugly grammer in programming
- Prev by Date: Re: single quotes, double quotes and "undefined index"
- Next by Date: watermark on .jpg, .gif, .png
- Previous by thread: mojavi - dokumentacja
- Next by thread: Re: Exception : an ugly grammer in programming
- Index(es):
Relevant Pages
|