hacioguz / solr-php-client

Automatically exported from code.google.com/p/solr-php-client
Other
0 stars 0 forks source link

Subclasses of Exception should be used instead of Exception #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the code throws instances of the Exception class. This makes it
hard to distinguish the exception source and cause in from the caller side.

With Exception subclasses you can do things like this:

try
{
  MyAppCall1();
  SomeOtherLibCall4('sfdsdf');
}
catch(MyApp_HttpException $ex)
{
  ...
}
catch(MyApp_Exception $ex)
{
  ...
}
catch(SomeOtherLib_Exception $ex)
{
  ...
}

I've added a diff which introduces the following exception hierarchy:

Exception
  - Apache_Solr_Exception
    - Apache_Solr_HttpTransportException (with HTTP 4xx or 5xx status code)
    - Apache_Solr_InvalidArgumentException
    - Apache_Solr_NoServiceAvailableException
    - Apache_Solr_ParserException

All of these exception classes are subclasses of Exception so it should not
break any existing code.

They should have been subclasses of PEAR_Exception if you'd want to follow
the PEAR guidelines:
http://pear.php.net/manual/en/standards.errors.php
But this project doesn't seem to aim to be a PEAR package so using it might
just introduce an unnecessary dependency on PEAR.

Original issue reported on code.google.com by mdbg....@gmail.com on 18 Feb 2010 at 7:40

Attachments:

GoogleCodeExporter commented 9 years ago
Patch applied and committed in revision 28

Original comment by donovan....@gmail.com on 19 Feb 2010 at 11:37