Skip to content

All exceptions should inherit from a base PHPEncoder\Exception #9

Open
@jmwebservices

Description

@jmwebservices

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions