我怎样才能做这种类型的抛出异常?
如果我有一个带有扩展名的文件.xlsx好的,如果我的文件扩展名是另一个抛出新的异常错误等
感谢您的支持
我必须在这里进行此控制
function getexceldata($excelfilepath){
$excelfilepath='/home/b2bmomo/test/esempio.xlsx';
if (!is_readable($excelfilepath))
{
throw new Exception('File ('.$excelfilepath.') not readable');
}
try {
异常文件路径可读后,我必须这样做
也许你正在寻找这个:
function getexceldata($excelfilepath){
$excelfilepath='/home/b2bmomo/test/esempio.xlsx';
if (!is_readable($excelfilepath))
{
throw new Exception('File ('.$excelfilepath.') not readable');
}
( ... )
}
try
{
$result = getexceldata( $excelfilepath );
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
否则,如果您正在寻找这种方式:
function getexceldata($excelfilepath){
$excelfilepath='/home/b2bmomo/test/esempio.xlsx';
try
{
if (!is_readable($excelfilepath))
{
throw new Exception('File ('.$excelfilepath.') not readable');
}
catch (Exception $e)
{
// Do something
}
}
请注意,这没有什么意义。请改用以下语法:
function getexceldata($excelfilepath){
$excelfilepath='/home/b2bmomo/test/esempio.xlsx';
if (!is_readable($excelfilepath))
{
// Do something
}
}