Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1192 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16345 invoked from network); 4 May 2003 00:53:40 -0000 Received: from unknown (HELO mailout11.sul.t-online.com) (194.25.134.85) by pb1.pair.com with SMTP; 4 May 2003 00:53:40 -0000 Received: from fwd10.sul.t-online.de by mailout11.sul.t-online.com with smtp id 19C7l6-0005dY-02; Sun, 04 May 2003 02:53:40 +0200 Received: from baumbart.marcus-boerger.de (520072483730-0001@[80.142.158.81]) by fwd10.sul.t-online.com with esmtp id 19C7l5-0eWEoiC; Sun, 4 May 2003 02:53:39 +0200 Reply-to:marcus.boerger@post.rwth-aachen.de Message-ID: <5.1.0.14.2.20030504021938.09452980@mailbox.rwth-aachen.de> X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Sun, 04 May 2003 02:53:30 +0200 To: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Sender: 520072483730-0001@t-dialin.net Subject: exceptions instead of errors From: marcus.boerger@t-online.de ((Marcus =?iso-8859-1?Q?B=F6rger?=)) The following patch: http://marcus-boerger.de/php/ext/exception.diff allows in a short, straight forward and easy way to suppress errors and optionally throw exceptions instead. This is supposed to be automated by the try opcode (but that is another discussion). The problem: During development of SQLite i found the problem that i had to inform the user about an error inside a constructor. This can only be done by throwing an exception. (Repeat: this cannot be done otherwise). The main problem herin is that we have many little utility functions that may raise errors (like safe mode and such). This means we had to rewrite the whole api, pass information around or find a generic solution. Ok here goes: First i fixed the "ignore repeated errors" feature. Then i added some control information to struct _php_core_globals: error_handling_t error_handling; zend_class_entry *exception_class; error_handling can be one of EH_NORMAL, EH_SUPPRESS and EH_THROW - EH_NORMAL is the normal way errors are handled - EH_SUPPRESS means the error is stored but not shown (suppressed even) - EH_THROW throws an exception of type PG(exception_class) or the default exception class if PG(exception_class) is NULL. To manually change the mode or class there is the following function: PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC) The mechanism itself is located in the function php_error_cb which is called during all error calls. So every error, warning or notice is catched. BUT of corse the mechanism doesn't work with E_ERROR, E_PARSE or such. These are real errors and are errors even after the patch. The reason the exception class can be set is to easily support exception inheritance for the lazy programmers. The reason to support EH_SUPPRESS is for more sophisticated problems... When the mechanismn throws an error it automatically sets these exception properties: - message the error message - file the filename - line the line number in the file Further more i suggest we add the severity to the default exception. Some help of the engine would be good: - automatically set EH_THROW mode at "try" - automatically set EH_NORMAL mode at "catch" (first outmost catch) If noone objects i will commit this on monday evening. Unfortunately there is a memory leak in the exception handling itself but that is another story...and will hopefully soon be fixed by somebody else. Anybody interested can try the patch with my patched SQLite: http://marcus-boerger.de/html/php/ext/sqlite/ and especially look into test sqlite_oo_020.phpt regards marcus -- ------------------->>> mailto:mail@marcus-boerger.de <<<------------------ "We are animals among animals, all children of matter, save that we are the more disarmed. But since, unlike animals, we know that we must die, let us prepare for that moment by enjoying the life that has been given us by chance and for chance." Umberto Eco, The island of the day before --------------------->>> http://marcus-boerger.de <<<---------------------