source: trunk/client/inc/hpdf5/spipu/html2pdf/doc/exception.md@ 384

Last change on this file since 384 was 347, checked in by roby, 3 years ago

Aggiornamento per compatibilità con php7.4

File size: 1.5 KB
Line 
1# Exception
2
3[back](./README.md)
4
5## Exceptions
6
7All the specific Html2Pdf exceptions are under the namespace `\Spipu\Html2Pdf\Exception`;
8
9Exception|Error Code|Additional Info|Description
10---------|----------|---------------|-----------
11Html2PdfException | 0 | | Occurs for every generic error during the process
12HtmlParsingException | 1 | <ul><li>getInvalidTag</li><li>getHtmlLine</li></ul> | Occurs if the html is no valid
13ImageException | 2 | <ul><li>getImage</li></ul> | Occurs if the asked image does not exist
14LongSentenceException | 3 | <ul><li>getSentence</li><li>getWidthBox</li><li>getLength</li></ul> | Occurs is a sentence is too long and does not fit in the current box
15TableException | 4 | | Occurs if the content of a TD does not fit on only one page
16
17## Exception Format
18
19An exception formatter can be used to display the exceptions: `\Spipu\Html2Pdf\Exception\ExceptionFormatter`.
20
21It takes the current exception as a parameter of the constructor.
22
23It provides 2 methods
24
25 * getMessage()
26 * getHtmlMessage();
27
28Usage example:
29
30```php
31try {
32 use Spipu\Html2Pdf\Html2Pdf;
33 use Spipu\Html2Pdf\Exception\Html2PdfException;
34 use Spipu\Html2Pdf\Exception\ExceptionFormatter;
35
36 $html2pdf = new Html2Pdf('P', 'A4', 'fr');
37 $html2pdf->setDefaultFont('Arial');
38 $html2pdf->writeHTML($htmlContent);
39 $html2pdf->output();
40} catch (Html2PdfException $e) {
41 $html2pdf->clean();
42
43 $formatter = new ExceptionFormatter($e);
44 echo $formatter->getHtmlMessage();
45}
46```
47
48[back](./README.md)
Note: See TracBrowser for help on using the repository browser.