如何捕获此异常(或phpoffice中的任何异常)
https://github.com/PHPOffice/PHPWord/tree/master/src/PhpWord
require_once \Ini::get('path/class').'/third-party/phpword/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
\PhpOffice\PhpWord\Settings::setPdfRendererPath(\Ini::get('path/class').'/third-party/tcpdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
try{
$word = \PhpOffice\PhpWord\IOFactory::load($file_dst);
$writer = \PhpOffice\PhpWord\IOFactory::createWriter($word, 'PDF');
}
catch(\PhpOffice\PhpWord\BadMethodCallException $e){
}
PHP Fatal error: Uncaught exception 'BadMethodCallException' with message 'Cannot add PreserveText in Cell.' in /var/www/dyntest.dk/class/third-party/phpword/Element/AbstractContainer.php:276
答案 0 :(得分:1)
多出一个base PHP Exception(PHP内核的一部分,而不是PHPOffice),你应该这样抓住它:
try{
$word = \PhpOffice\PhpWord\IOFactory::load($file_dst);
$writer = \PhpOffice\PhpWord\IOFactory::createWriter($word, 'PDF');
}
catch(\BadMethodCallException $e){
}