1. Go to this page and download the library: Download hoa/exception library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hoa / exception example snippets
$exception = new Hoa\Exception\Exception('Hello %s!', 0, 'world');
$previous = new Hoa\Exception\Exception('Hello previous.');
$exception = new Hoa\Exception\Exception('Hello %s!', 0, 'world', $previous);
echo $exception->raise(true);
/**
* Will output:
* {main}: (0) Hello world!
* in … at line ….
*
* ⬇
*
* Nested exception (Hoa\Exception\Exception):
* {main}: (0) Hello previous.
* in … at line ….
*/
// A group of exceptions.
$group = new Hoa\Exception\Group('Failed because of several reasons.');
$group['first'] = new Hoa\Exception\Exception('First reason');
$group['second'] = new Hoa\Exception\Exception('Second reason');
// Can nest another group.
$group['third'] = new Hoa\Exception\Group('Third reason');
$group['third']['fourth'] = new Hoa\Exception\Exception('Fourth reason');
echo $group->raise(true);
/**
* Will output:
* {main}: (0) Failed because of several reasons.
* in … at line ….
*
* Contains the following exceptions:
*
* • {main}: (0) First reason
* in … at line ….
*
* • {main}: (0) Second reason
* in … at line ….
*
* • {main}: (0) Third reason
* in … at line ….
*
* Contains the following exceptions:
*
* • {main}: (0) Fourth reason
* in … at line ….
*/
$group = new Hoa\Exception\Group('Failed because of several reasons.');
$group[] = new Hoa\Exception\Exception('Always present.');
$group->beginTransaction();
$group[] = new Hoa\Exception\Exception('Might be present.');
if (true === $condition) {
$group->commitTransaction();
} else {
$group->rollbackTransaction();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.