[PHP] Exception Handling

2012-06-01 Thread James Colannino

Hey guys,

Haven't posted in a long time...  Happy Memorial Day!  I have an issue 
with exception handling.  I'm using a framework that throws a 
Database_Exception object.  I was expecting catch (Exception $var) to 
be sufficient to catch this, but it doesn't.  I have to do catch 
(Database_Exception $var) to make it work.  I've been reading that 
Exception should be sufficient, since every exception object is a child 
class of Exception.  Did this perhaps change in 5.4?  I think it was 
working properly in 5.3, but I'm not sure.


Any clarification would be greatly appreciated!

James

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception Handling

2012-06-01 Thread ma...@behnke.biz

James Colannino crankycycl...@gmail.com hat am 1. Juni 2012 um 16:25
geschrieben:

 Hey guys,

 Haven't posted in a long time...  Happy Memorial Day!  I have an issue
 with exception handling.  I'm using a framework that throws a
 Database_Exception object.  I was expecting catch (Exception $var) to
 be sufficient to catch this, but it doesn't.  I have to do catch
 (Database_Exception $var) to make it work.  I've been reading that
 Exception should be sufficient, since every exception object is a child
 class of Exception.  Did this perhaps change in 5.4?  I think it was
 working properly in 5.3, but I'm not sure.


Look at the definition of Database_Exception and see if it extends Exception,
I'll guess it doesn't.
Nothing changed in PHP 5.4 to that.


 Any clarification would be greatly appreciated!

 James

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Exception Handling

2012-06-01 Thread Mackintosh, Mike
-Original Message-
From: James Colannino [mailto:crankycycl...@gmail.com] 
Sent: Friday, June 01, 2012 10:25 AM
To: PHP-General List
Subject: [PHP] Exception Handling

Hey guys,

Haven't posted in a long time...  Happy Memorial Day!  I have an issue
with exception handling.  I'm using a framework that throws a
Database_Exception object.  I was expecting catch (Exception $var) to
be sufficient to catch this, but it doesn't.  I have to do catch
(Database_Exception $var) to make it work.  I've been reading that
Exception should be sufficient, since every exception object is a child
class of Exception.  Did this perhaps change in 5.4?  I think it was
working properly in 5.3, but I'm not sure.

Any clarification would be greatly appreciated!

James

--

Hi James,

You would have to catch Database_Exception. It is also good practice to
also always catch exception afterwards.

Ex:

Class Database_Exception extends Exception{
Public function __construct($message){
parent::__construct($message);
}
}

Try{
$pdo = new PDO();
If($pdo === false){
Throw new Database_Exception(Failed To Connect);
}
}
Catch(Database_Exception $e){
Echo $e-getMessage();
}
Catch(Exception $e){
Echo $e-getMessage();
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception Handling

2012-06-01 Thread James Colannino

On 06/01/12 07:30, ma...@behnke.biz wrote:

James Colanninocrankycycl...@gmail.com  hat am 1. Juni 2012 um 16:25
geschrieben:

Hey guys,

Haven't posted in a long time...  Happy Memorial Day!  I have an issue
with exception handling.  I'm using a framework that throws a
Database_Exception object.  I was expecting catch (Exception $var) to
be sufficient to catch this, but it doesn't.  I have to do catch
(Database_Exception $var) to make it work.  I've been reading that
Exception should be sufficient, since every exception object is a child
class of Exception.  Did this perhaps change in 5.4?  I think it was
working properly in 5.3, but I'm not sure.

Look at the definition of Database_Exception and see if it extends Exception,
I'll guess it doesn't.
Nothing changed in PHP 5.4 to that.



Hey Marco,

Thanks for the reply!  That was the first thing I checked.

class Database_Exception extends \FuelException {}
class Fuel_Exception extends \Exception {}

It's extending Exception, as expected.  Also, can you throw classes that 
don't extend Exception?  It was always my understanding that doing so 
would cause a fatal error.


James

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception Handling

2012-06-01 Thread James Colannino

On 06/01/12 08:08, James Colannino wrote:

On 06/01/12 07:30, ma...@behnke.biz wrote:

James Colanninocrankycycl...@gmail.com  hat am 1. Juni 2012 um 16:25
geschrieben:

Hey guys,

Haven't posted in a long time...  Happy Memorial Day!  I have an issue
with exception handling.  I'm using a framework that throws a
Database_Exception object.  I was expecting catch (Exception $var) to
be sufficient to catch this, but it doesn't.  I have to do catch
(Database_Exception $var) to make it work.  I've been reading that
Exception should be sufficient, since every exception object is a child
class of Exception.  Did this perhaps change in 5.4?  I think it was
working properly in 5.3, but I'm not sure.
Look at the definition of Database_Exception and see if it extends 
Exception,

I'll guess it doesn't.
Nothing changed in PHP 5.4 to that.



Hey Marco,

Thanks for the reply!  That was the first thing I checked.

class Database_Exception extends \FuelException {}
class Fuel_Exception extends \Exception {}

It's extending Exception, as expected.  Also, can you throw classes 
that don't extend Exception?  It was always my understanding that 
doing so would cause a fatal error.


I was right.  From the documentation 
(http://php.net/manual/en/language.exceptions.php):


The thrown object must be an instance of the Exception 
http://www.php.net/manual/en/class.exception.php class or a subclass 
of Exception http://www.php.net/manual/en/class.exception.php. Trying 
to throw an object that is not will result in a PHP Fatal Error.


James


Re: [PHP] Exception Handling

2012-06-01 Thread James Colannino

On 06/01/12 07:32, Mackintosh, Mike wrote:

Hi James,

You would have to catch Database_Exception. It is also good practice to
also always catch exception afterwards.



Hey Mike,

Thanks for the reply!  I saw this comment in the documentation 
(http://www.php.net/manual/en/language.exceptions.extending.php) -- it's 
the first one:


|It's important to note that subclasses of the Exception class will be 
caught by the default Exception handler


Of course, I haven't tested the code they posted.  I'll do that tonight 
and confirm or deny the expected result.


James
|


RE: [PHP] Exception Handling

2012-06-01 Thread Mackintosh, Mike
-Original Message-
From: James Colannino [mailto:crankycycl...@gmail.com] 
Sent: Friday, June 01, 2012 11:14 AM
To: PHP-General List
Subject: Re: [PHP] Exception Handling

Hey Mike,

Thanks for the reply!  I saw this comment in the documentation
(http://www.php.net/manual/en/language.exceptions.extending.php) -- it's
the first one:

|It's important to note that subclasses of the Exception class will be
caught by the default Exception handler

Of course, I haven't tested the code they posted.  I'll do that tonight
and confirm or deny the expected result.

James
|

Well look at that..

class James_Exception extends \Exception{
function __construct($message){
parent::__construct($message);
}
}

try{
throw new James_Exception('Testing Exception Catch-All');
}
catch(Exception $e){
print_r($e);
}

Output:

James_Exception Object
(
[message:protected] = Testing Exception Catch-All...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception Handling

2012-06-01 Thread FeIn
Maybe catch(Exception $e) should be catch(\Exception $e)?

On Fri, Jun 1, 2012 at 5:25 PM, James Colannino crankycycl...@gmail.com wrote:
 Hey guys,

 Haven't posted in a long time...  Happy Memorial Day!  I have an issue with
 exception handling.  I'm using a framework that throws a
 Database_Exception object.  I was expecting catch (Exception $var) to be
 sufficient to catch this, but it doesn't.  I have to do catch
 (Database_Exception $var) to make it work.  I've been reading that Exception
 should be sufficient, since every exception object is a child class of
 Exception.  Did this perhaps change in 5.4?  I think it was working properly
 in 5.3, but I'm not sure.

 Any clarification would be greatly appreciated!

 James

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception Handling

2012-06-01 Thread Marco Behnke
Am 01.06.12 17:08, schrieb James Colannino:

 Hey Marco,

 Thanks for the reply!  That was the first thing I checked.

 class Database_Exception extends \FuelException {}
 class Fuel_Exception extends \Exception {}

 It's extending Exception, as expected.  Also, can you throw classes
 that don't extend Exception?  It was always my understanding that
 doing so would cause a fatal error.

Ah, I guess that is the problem. Your application framework uses namespaces.
I guess you should try

catch (\Exception $e)

instead of

catch (Exception $e)

:-)


 James



-- 
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz




signature.asc
Description: OpenPGP digital signature


Re: [PHP] Exception Handling

2012-06-01 Thread James Colannino
On Fri, Jun 1, 2012 at 12:51 PM, Marco Behnke ma...@behnke.biz wrote:

Ah, I guess that is the problem. Your application framework uses namespaces.
 I guess you should try

 catch (\Exception $e)

 instead of

 catch (Exception $e)

 :-)


Ah, that was probably it.  Will try it out tonight to confirm.  Thanks!

James


Re: [PHP] Re: php exception handling

2009-10-12 Thread kranthi
cant http://us3.php.net/manual/en/function.set-exception-handler.php be used ?

?php
function exception_handler($e) {
//mail('to', 'exception', $e-getMessage());
}
set_exception_handler('exception_handler');

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php exception handling

2009-10-11 Thread Lars Nielsen
Hi,

I am trying to make an exception class that emails the errors to myself.
I have started by using the example by ask at nilpo dot com on
http://dk2.php.net/manual/en/language.exceptions.php.

It work ok but i want it NOT to show the errors on the php-page but only
show the details in the email and then just write eg An error occurred
or so on the webpage. Can anyone give me a hint about how to achieve
this?

Regards 
Lars Nielsen


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php exception handling

2009-10-11 Thread Tommy Pham
- Original Message 
 From: Lars Nielsen l...@mit-web.dk
 To: php-general@lists.php.net
 Sent: Sun, October 11, 2009 2:18:03 PM
 Subject: [PHP] php exception handling
 
 Hi,
 
 I am trying to make an exception class that emails the errors to myself.
 I have started by using the example by ask at nilpo dot com on
 http://dk2.php.net/manual/en/language.exceptions.php.
 
 It work ok but i want it NOT to show the errors on the php-page but only
 show the details in the email and then just write eg An error occurred
 or so on the webpage. Can anyone give me a hint about how to achieve
 this?
 
 Regards 
 Lars Nielsen
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

Lars,

Here's a pseudo code:

try {
  if (!$valid) {
throw new Exception(Test failed.);
  } else {
   // do something
  }
} catch (Exception $e) {
  // set/print a user friendly message to send to output

  // set a detailed message using debug_backtrace() or any other information 
relevant for easier troubleshooting
  // log and/or email detailed message
}

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php exception handling

2009-10-11 Thread Larry Garfield
On Sunday 11 October 2009 6:09:46 pm Tommy Pham wrote:

 Lars,

 Here's a pseudo code:

 try {
   if (!$valid) {
 throw new Exception(Test failed.);
   } else {
// do something
   }
 } catch (Exception $e) {
   // set/print a user friendly message to send to output

   // set a detailed message using debug_backtrace() or any other
 information relevant for easier troubleshooting // log and/or email
 detailed message
 }

 Regards,
 Tommy

Actually the else clause is not necessary.  That's one of the nice things 
about exceptions.  If you throw an exception, processing jumps to the 
appropriate catch and never returns.  

try {
  // Do normal stuff.

  if (!$valid) {
throw new Exception('OMG!');
  }

  // Do more normal stuff.
}
catch (Exception $e) {
  // Print user friendly message.
  // Log detailed information or whatever you're going to do.
}


-- 
Larry Garfield
la...@garfieldtech.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php exception handling

2009-10-11 Thread Al



Lars Nielsen wrote:

Hi,

I am trying to make an exception class that emails the errors to myself.
I have started by using the example by ask at nilpo dot com on
http://dk2.php.net/manual/en/language.exceptions.php.

It work ok but i want it NOT to show the errors on the php-page but only
show the details in the email and then just write eg An error occurred
or so on the webpage. Can anyone give me a hint about how to achieve
this?

Regards 
Lars Nielsen




Don't sell exception handling short; it can be very useful for processing 
control.  Here is an example of a sequence of user input validations and checks.


All check functions throw an exception, with the details, if they find an error. 
e.g., Tag spen is invalid. Check spelling. This message is rendered so the 
user can correct his/her mistake.


if(!empty($adminMiscSettingsArray['instrText']))
{
 try{
  checkValidTags($validHTMLtags, 
allProxyTagsArray,adminMiscSettingsArray['instrText']);


  checkTagMatching($emptyProxyTagsArray,$adminMiscSettingsArray['instrText']);
  checkTagNesting($emptyProxyTagsArray, $adminMiscSettingsArray['instrText']);
  checkTextLinks($linksProxyTagsArray, $adminMiscSettingsArray['instrText']);
  }
 catch (Exception $e){
   $instrCheckErrorMsg = $e-getMessage();
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling with file()

2008-02-14 Thread Richard Lynch
On Mon, February 11, 2008 6:34 am, John Papas wrote:
 I need to open a remote file with file() and I would like to put it
 inside a try-catch but as far as I can tell file() does not raise an
 exception if it fails. The following code:

   try {
  $data = file('http://myserver.com/myfile.txt');
  $date = substr($data, 0);
   } catch (Exception $e) {
  $data = it failed;
   }

   echo $data;

 echoes a warning:

   Warning: file('http://myserver.com/myfile.txt') [function.file]:
 failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
 in.

Old-school PHP functions do not (and will not) raise exceptions.

Use http://php.net/set_error_handler

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Exception handling with file()

2008-02-11 Thread John Papas
I need to open a remote file with file() and I would like to put it
inside a try-catch but as far as I can tell file() does not raise an
exception if it fails. The following code:

try {
   $data = file('http://myserver.com/myfile.txt');
   $date = substr($data, 0);
} catch (Exception $e) {
   $data = it failed;
}

echo $data;

echoes a warning:

Warning: file('http://myserver.com/myfile.txt') [function.file]:
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling with file()

2008-02-11 Thread Zoltán Németh
2008. 02. 11, hétfő keltezéssel 14.34-kor John Papas ezt írta:
 I need to open a remote file with file() and I would like to put it
 inside a try-catch but as far as I can tell file() does not raise an
 exception if it fails. The following code:
 
   try {
  $data = file('http://myserver.com/myfile.txt');
$data = @file('http://myserver.com/myfile.txt');
if ($data === FALSE) throw new Exception('whatever');


hope that helps
Zoltán Németh

  $date = substr($data, 0);
   } catch (Exception $e) {
  $data = it failed;
   }
   
   echo $data;
 
 echoes a warning:
 
   Warning: file('http://myserver.com/myfile.txt') [function.file]:
 failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
 in.
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling in PHP

2008-02-07 Thread Paul Scott

On Wed, 2008-02-06 at 23:37 -0800, Prabath Kumarasinghe wrote:
 Does that mean for every exception do we have to write
 our custom exception and describe it from our own
 message
 

No, it means that when you want to throw a meaningful exception, you
need to type in a message. I mentioned custom exceptions, because that
is what I do, as I multilingualise my messages and do other things with
the exception, like display an XHTML page to the users.

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Exception handling in PHP

2008-02-07 Thread Prabath Kumarasinghe
Understood, Thanks Paul

Cheers
Prabath
--- Paul Scott [EMAIL PROTECTED] wrote:

 
 On Wed, 2008-02-06 at 23:37 -0800, Prabath
 Kumarasinghe wrote:
  Does that mean for every exception do we have to
 write
  our custom exception and describe it from our own
  message
  
 
 No, it means that when you want to throw a
 meaningful exception, you
 need to type in a message. I mentioned custom
 exceptions, because that
 is what I do, as I multilingualise my messages and
 do other things with
 the exception, like display an XHTML page to the
 users.
 
 --Paul
 
  All Email originating from UWC is covered by
 disclaimer 

http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
 
 



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling in PHP

2008-02-07 Thread Paul Scott


On Thu, 2008-02-07 at 00:20 -0800, Prabath Kumarasinghe wrote:
 Understood, Thanks Paul
 

Pleasure, but please don't top post, it makes it really hard to follow a
thread easily. Most people on this list take time out from their really
busy day jobs to help out, and the more time that everyone can save
them, the better.

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Exception handling in PHP

2008-02-07 Thread Richard Heyes

Does that mean for every exception do we have to write
our custom exception and describe it from our own
message


If you mean Do I have to write custom exception classes?, the no. You 
could just use the PHP Exception class.


Eg.

class DBException extends Exception {}

try {
$connection = mysql_connect(...);

if (!$connection) {
throw new DBException('Failed to connect to database');
}

// Database exception handling code
} catch (DBException $e) {
// ...

// Generic Exception handling code (The Exception c
} catch Exception $e {
// ...
}

That's from memory, so there may be a few errors.

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and Helpdesk software for £299 hosted for you -
no installation, no maintenance, new features automatic and free

 ** New Helpdesk demo now available **

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling in PHP

2008-02-07 Thread Richard Heyes

// ...

That's from memory, so there may be a few errors.


Seems there was. Try this:

class DBException extends Exception {}

try {
$connection = mysql_connect(...);

if (!$connection) {
throw new DBException('Failed to connect to database');
}

// Database exception handling code
} catch (DBException $e) {
// ...

// Generic Exception handling code (The Exception class is
// built in to PHP)
} catch (Exception $e) {
// ...
}

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and Helpdesk software for £299 hosted for you -
no installation, no maintenance, new features automatic and free

 ** New Helpdesk demo now available **

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Exception handling in PHP

2008-02-06 Thread Prabath Kumarasinghe
Hi All

I'm little bit confusing with PHP exception handling.
Could you able to explain how to put try{} and
catch(){}  in a proper way in PHP. I had already read
php exception manual but it didn't help me to get
exact idea about exception handling in php.

Cheers

Prabath


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling in PHP

2008-02-06 Thread Paul Scott

On Wed, 2008-02-06 at 22:52 -0800, Prabath Kumarasinghe wrote:
 Hi All
 
 I'm little bit confusing with PHP exception handling.
 Could you able to explain how to put try{} and
 catch(){}  in a proper way in PHP. I had already read
 php exception manual but it didn't help me to get
 exact idea about exception handling in php.
 

Well, its pretty simple really...

In your objects that you create, just put in a statement that throws an
exception of some sort (I like to extend the built in exception handler
with a custom one that deals properly with db errors as well as PHP
ones) and then try{} and catch(){} them in your business logic.

example:

class someclass {

public function foo()
{
 // do something
 ...
 else {
 throw new Exception(uh-oh - we have a problem!);
 }
}

}

$thing = new someclass;
try {
$thing-foo();
}
catch(Exception $e) {
echo $e-getMessage();
exit;
}

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Exception handling in PHP

2008-02-06 Thread Prabath Kumarasinghe
Hi Paul

Is this following code work in PHP if mysql_connect
fails.

try{
mysql_connect('localhost','user','');

}catch(Exception $e){
  echo $e-getMessage();

}

Cheers

Prabath

--- Paul Scott [EMAIL PROTECTED] wrote:

 
 On Wed, 2008-02-06 at 22:52 -0800, Prabath
 Kumarasinghe wrote:
  Hi All
  
  I'm little bit confusing with PHP exception
 handling.
  Could you able to explain how to put try{} and
  catch(){}  in a proper way in PHP. I had already
 read
  php exception manual but it didn't help me to get
  exact idea about exception handling in php.
  
 
 Well, its pretty simple really...
 
 In your objects that you create, just put in a
 statement that throws an
 exception of some sort (I like to extend the built
 in exception handler
 with a custom one that deals properly with db errors
 as well as PHP
 ones) and then try{} and catch(){} them in your
 business logic.
 
 example:
 
 class someclass {
 
 public function foo()
 {
  // do something
  ...
  else {
  throw new Exception(uh-oh - we have a
 problem!);
  }
 }
 
 }
 
 $thing = new someclass;
 try {
 $thing-foo();
 }
 catch(Exception $e) {
 echo $e-getMessage();
 exit;
 }
 
 --Paul
 
  All Email originating from UWC is covered by
 disclaimer 

http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
 
 
  -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Exception handling in PHP

2008-02-06 Thread Paul Scott

On Wed, 2008-02-06 at 23:10 -0800, Prabath Kumarasinghe wrote:
 Is this following code work in PHP if mysql_connect
 fails.
 
 try{
 mysql_connect('localhost','user','');
 
 }catch(Exception $e){
   echo $e-getMessage();
 

Probably not. I don't think that the mysql functions throw exceptions on
failure. 

You will have to write a wrapper function to do the exception on
failure, so something like

function dbConnect()
{
   $conn = mysql_connect('','','');
   if(!$conn) {
   throw new Exception(Couldn't connect);
   }
   else {
   return $conn;
   }
}

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Exception handling in PHP

2008-02-06 Thread Prabath Kumarasinghe
Does that mean for every exception do we have to write
our custom exception and describe it from our own
message

Cheers

Prabath 
--- Paul Scott [EMAIL PROTECTED] wrote:

 
 On Wed, 2008-02-06 at 23:10 -0800, Prabath
 Kumarasinghe wrote:
  Is this following code work in PHP if
 mysql_connect
  fails.
  
  try{
  mysql_connect('localhost','user','');
  
  }catch(Exception $e){
echo $e-getMessage();
  
 
 Probably not. I don't think that the mysql functions
 throw exceptions on
 failure. 
 
 You will have to write a wrapper function to do the
 exception on
 failure, so something like
 
 function dbConnect()
 {
$conn = mysql_connect('','','');
if(!$conn) {
throw new Exception(Couldn't connect);
}
else {
return $conn;
}
 }
 
  All Email originating from UWC is covered by
 disclaimer 

http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm
 
 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Exception Handling in php

2001-02-28 Thread Ovidiu EFTIMIE

I think that would be nice to have a try-catch to better control of the
code.

Ovidiu

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, February 27, 2001 9:09 PM
 To: kevin1; [EMAIL PROTECTED]
 Subject: Re: [PHP] Exception Handling in php


 Addressed to: kevin1 [EMAIL PROTECTED]
   [EMAIL PROTECTED]

 ** Reply to note from kevin1 [EMAIL PROTECTED] Tue, 27 Feb
 2001 08:10:05 -0500
 
  Is there any equivalent to Java's try-catch or Perl's eval{BLOCK}if($@)
  structure in PHP?

 No.

 There has been some discussion about adding it on the developers list,
 but I don't expect to see it any time soon.




 Rick Widmer
 Internet Marketing Specialists
 http://www.developersdesk.com

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Exception Handling in php

2001-02-27 Thread kevin1

Is there any equivalent to Java's try-catch or Perl's eval{BLOCK}if($@) 
structure in PHP?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Exception Handling in php

2001-02-27 Thread php3

Addressed to: kevin1 [EMAIL PROTECTED]
  [EMAIL PROTECTED]

** Reply to note from kevin1 [EMAIL PROTECTED] Tue, 27 Feb 2001 08:10:05 -0500

 Is there any equivalent to Java's try-catch or Perl's eval{BLOCK}if($@)
 structure in PHP?

No.

There has been some discussion about adding it on the developers list,
but I don't expect to see it any time soon.




Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Exception handling

2001-02-15 Thread Alain Fontaine

Hello,

Is it impolite to ask about when approximately PHP will support Exception
handling ? :)

Thanks !



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]