Best way to handle errors on a php page?

后端 未结 8 743
傲寒
傲寒 2020-11-30 22:10

Right now my pages look something like this:

if($_GET[\'something\'] == \'somevalue\')
{
    $output .= \'somecode\';

    // make a DB query, fetch a row
           


        
8条回答
  •  臣服心动
    2020-11-30 22:32

    PDO error exception handling for queries, and really all code should be run through:

    try{
    
    }
    
    catch{
    
    
    }
    
    finally{
    
    }
    

    The reason for this, is it makes debugging much easier when you can pinpoint roughly where in lengthy scripts an error is occuring

    more info here: http://php.net/manual/en/language.exceptions.php

提交回复
热议问题