# Exceptions and builtin functions in PHP5

- Thread: https://externals.io/message/8990
- Original archive: https://news-web.php.net/php.internals/8990
- Started by Tumurbaatar S. on 2004-04-08T10:17:05+00:00
- Messages: 6
- 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

---

## #8990 — Tumurbaatar S. — 2004-04-08T10:17:05+00:00

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

----- Original Message ----- 
From: "Tumurbaatar S." <tumurbaatar@datacom.mn>
Newsgroups: php.general
Sent: Thursday, April 08, 2004 17:44
Subject: Re: [PHP] Exceptions and builtin functions in PHP5


>
> <daniel@electroteque.org> wrote in message
> news:49201.203.15.102.65.1081404627.squirrel@www.electroteque.org...
> > […]
>

 In the current version of PHP, many built-in functions (if not all?)
 return `FALSE` on an error and some resource/handle on a success.
 So, instead of coding like this:
 ...
     $res = some_builtin_func(); // func does not raise exception on error
     if (!$res)
         throw new Exception();    // so I throw it manually
 ...
 I want to write:
 ...
     $res = some_builtin_func(); // func raises exception on error
 // so I don't need to write additional lines
 ...

 So will PHP5 (or future versions) work as in my 2nd example?

---

## #8991 — Derick Rethans — 2004-04-08T10:45:41+00:00

URL: https://externals.io/message/8990#8991 · In reply to: #8990

> > […]

<snip>

>  I want to write:
>  ...
>      $res = some_builtin_func(); // func raises exception on error
>  // so I don't need to write additional lines
>  ...
>
>  So will PHP5 (or future versions) work as in my 2nd example?

No

regards,
Derick

---

## #8992 — Ferdinand Beyer — 2004-04-08T11:05:36+00:00

URL: https://externals.io/message/8990#8992 · In reply to: #8990

> > […]
> 
> No

It would be a nice feature to let the user decide whether to throw 
exceptions when errors are triggered:

// either ERROR_TRIGGER or ERROR_EXCEPTION
error_handling(ERROR_EXCEPTION);

// Don't throw exceptions for notices or warnings
error_reporting(E_ERROR);

try {
    mysql_connect()
}
catch (Notice $e) {
    echo 'Notice: ' . $e->getMessage();
}
catch (Warning $e) {
    echo 'Warning: ' . $e->getMessage();
}
catch (Error $e) {
    echo 'Error: ' . $e->getMessage();
}
catch (Exception $e) {
    echo 'Unknown exception: ' . $e->getMessage();
}

-- 
Ferdinand Beyer
<fb@fbeyer.com

---

## #8993 — Tumurbaatar S. — 2004-04-08T11:06:51+00:00

URL: https://externals.io/message/8990#8993 · In reply to: #8991

"Derick Rethans" <derick@php.net> wrote in message
news:Pine.LNX.4.58.0404081244590.9058@localhost...
> 
>
> > […]
>
> <snip>
>
> > […]
>
> No
>
> regards,
> Derick

"Zend Engine. Version 2. Feature Overview and Design." PDF says
that:
...
Compatibility notes
No compatibility problems exist, as this feature doesn't exist in previous
versions of the
scripting engine. In order to simplify error handling in the existing code
base, the engine
will support a mode in which errors (such as `E_WARNING` and E_NOTICE) will
raise
exceptions, instead of displaying an error. This will allow users to use one
try..catch
statement to recover from any possible errors during the course of a large
code block
(e.g., establishing a connection to a database server, selecting a database,
and issuing a
query), without having to add lots of error-handling code.
...

Is it not what I'm talking about?

---

## #8994 — Derick Rethans — 2004-04-08T11:07:38+00:00

URL: https://externals.io/message/8990#8994 · In reply to: #8992

> 
>
> > […]
>
> It would be a nice feature to let the user decide whether to throw
> exceptions when errors are triggered:

NO!

Derick

---

## #8995 — Derick Rethans — 2004-04-08T11:08:19+00:00

URL: https://externals.io/message/8990#8995 · In reply to: #8993

> Is it not what I'm talking about?

This document is outdated in much more things then only this. Forget
about it.

Derick
