Open
Description
Thanks for this project. I have been using it for several months to prettify a configuration array that is modified by a UI and written to a file.
It would be nice if all exceptions thrown by PHPEncoder would inherit from a base PHPEncoder\Exception class. Currently, InvalidOptionException
is the only PHPEncoder specific exception while InvalidArgumentException
and RuntimeException
are thrown directly. Implementing this recommendation will make it possible to distinguish between PHPEncoder exceptions and other exceptions thrown by an app using PHPEncoder (see example below).
public function write( $content ) : bool
{
try
{
if( !$this->validate( $content ) )
throw new APP_Exception( 'SOME USEFUL MESSAGE.' );
$put = ( new \Riimu\Kit\PHPEncoder\PHPEncoder )->encode( $content );
if( file_put_contents( $this->path(), $put ) === false )
throw new APP_Exception( 'SOME USEFUL MESSAGE.' );
}
catch( APP_Exception $e )
{
// do something with APP thrown exception
}
catch( \Riimu\Kit\PHPEncoder\Exception $e )
{
// do something with PHPEncoder thrown exception
}
return true;
}
Metadata
Metadata
Assignees
Labels
No labels