Why isn't my Exception being caught by catch?

前端 未结 4 562
梦毁少年i
梦毁少年i 2020-12-18 18:55

I have some code that looks like this

# Try to import file
try
{
    DataManager::fileImport($_FILES[\'datafile\'][\'tmp_name\'], 
                                   


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-18 19:28

    You might have an issue with your DataManager class because i copied your code, adapted it to run and i get the exception handled... You problem is elsewhere...

    class DataManager {
        static function fileImport($filepath, $zones, $statuses){
            throw new Exception('SOME EXCEPTION');
        }
    }
    
    try{
        DataManager::fileImport('', '', '');
    }catch(Exception $e){
        print 'Herp.';
    }
    

    Results in

    Herp.
    

提交回复
热议问题