# try/catch/FINALLY

- Thread: https://externals.io/message/3747
- Original archive: https://news-web.php.net/php.internals/3747
- Started by Cristiano Duarte on 2003-08-06T00:15:39+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #3747 — Cristiano Duarte — 2003-08-06T00:15:39+00:00

URL: https://externals.io/message/3747#3747

Hi all,

I know there was a lot of discussion about try/catch, but I will bring it up
again:

What about finally ?

I know someone posted that finally isn't necessary since PHP destroy all
variables and releases all resources at the end of the script. But if the
script is a PHP-GTK application or a standalone server aplication (like
CORBA)?

Finally is very useful in situations where you must be certain that some
piece of code will be executed no matter what happens (a normal execution, a
return statement or an exception).

IMHO I think that an implementation start would be hooking the function exit
at the engine..

Cristiano Duarte

---

## #3748 — Cristiano Duarte — 2003-08-06T00:25:52+00:00

URL: https://externals.io/message/3747#3748 · In reply to: #3747

Please, ignore this:
> IMHO I think that an implementation start would be hooking the function
exit
> at the engine..

And read this instead:
IMHO I think that an implementation start would be hooking the exit of the
try statement even if its normal or has an exception thrown...

Best regards,

Cristiano Duarte

"Cristiano Duarte" <cunha17@uol.com.br> escreveu na mensagem
news:20030806001540.7978.qmail@pb1.pair.com...
> Hi all,
>
> I know there was a lot of discussion about try/catch, but I will bring it
up
> again:
>
> What about finally ?
>
> I know someone posted that finally isn't necessary since PHP destroy all
> variables and releases all resources at the end of the script. But if the
> script is a PHP-GTK application or a standalone server aplication (like
> CORBA)?
>
> Finally is very useful in situations where you must be certain that some
> piece of code will be executed no matter what happens (a normal execution,
a
> return statement or an exception).
>
> IMHO I think that an implementation start would be hooking the function
exit
> at the engine..
>
> Cristiano Duarte

---

## #3758 — Wez Furlong — 2003-08-06T08:12:31+00:00

URL: https://externals.io/message/3747#3758

The most important thing missing from this is that you cannot rethrow the
exception from the point where you suggest to place the finally code :-)

--Wez.

> There's absolute no need for finally:
>
> try {
> }
> catch (...) {
> }
> // here's you're finally code

---

## #3757 — Simeon Koptelov — 2003-08-06T08:56:51+00:00

URL: https://externals.io/message/3747#3757

Hello Marcus,

Wednesday, August 6, 2003, 1:14:10 PM, you wrote:

CD>> What about finally ?

MB> There's absolute no need for finally:

MB> try {
MB> }
MB> catch (...) {
MB> }
MB> // here's you're finally code

try
{
   $this->allocateSomeResources();
   throw new SomeException();
}
catch( AnotherException $e )
{
}
finally
{
   $this->freeSomeResource();
}

This code will call freeSomeResource() -- that's why one may want to
have finally.

But I agree that there's no need for finally. If uncaught exception
is thrown -- it's bad application design or
malicious component( you cannot declare throws in function definition
so some evil component can do something like
" throw new ExceptionThatNobodyHandles(); // har-har-har!" .
You need to refactor in first case and
can do nothing in second -- if you'll start to free resources in
finally after each try-catch or always catch Exception,
your code will become garbage soon IMHO.

-- 
Best regards,
 Simeon                            mailto:xi@newmail.ru

---

## #3759 — Simeon Koptelov — 2003-08-06T09:22:26+00:00

URL: https://externals.io/message/3747#3759 · In reply to: #3747

Hello Cristiano,

Wednesday, August 6, 2003, 6:15:39 AM, you wrote:

It would be much better if user will have to put method's throws in
method's declaration imho( see my reply to Marcus ).

-- 
Best regards,
 Simeon                            mailto:xi@newmail.ru
