• 一段PHP异常


    这是我写的一段代码,里面通过PHP异常功能,实现报错时显示出错代码所在行。当使用者操作出错时,截图给我,我可以很快得去追踪和排查错误!

    public function added_business_submit(){
        try{
            extract($_POST);
            if(''==$title)          self::json(0,sprintf(ERROR_EMPTY,'工单标题'));
            if(''==$is_trusteeship) self::json(0,sprintf(ERROR_EMPTY,'服务器类别'));
            if(''==$eqroom_id)      self::json(0,sprintf(ERROR_EMPTY,'所在机房'));
            
            M()->startTrans();
            $com_info     = M('company')->where(array('com_qyuserid'=>$com_qyuserid))->find();
            $com_id       = $com_info['com_id'];
            $com_name     = $com_info['com_name'];    
            if(empty($com_info)) throw new Exception(ERROR_NOTFOUND_USER);
            
            $data = array(
                'com_id'       => $com_id,
                'com_name'     => $com_name,
                'type'         => 1,
                'step'         => 1,
                'poster'       => self::$user['name'],
                'posttime'     => self::$datetime,
                'eqroom_name'  => D('EquipRoom')->get_eqroom_name($eqroom_id),
            );
            $data = array_merge($data,$_POST);
            $agent_id = M('working_agent')->add($data);
            if(false===$agent_id) throw new Exception(ERROR_SUBMIT);
            
            $result = D('StepLogAgent')->next_step($agent_id,$remark);
            if(false===$result) throw new Exception(ERROR_SUBMIT);
        }catch(Exception $e){
            M()->rollback();
            $this->exception_handle($e);
        }
    
        M()->commit();
        self::json(1,SUCCESS_SUBMIT);
    }
    
    private function exception_handle(Exception $e){
        $msg  = $e->getMessage();
        $line = $e->getLine();
        //**/print_r($e); echo M()->getLastSql();
        $name = self::$user['name'];
        $time = self::$datetime;
        $sql  = M()->getLastSql();
        $log  = $time." ".$name.":{$msg}({$line}) {$sql}";
        self::mylog($log,'Agent');
        self::json(0,"{$msg}({$line})");
    }
  • 相关阅读:
    HDU 5835 Danganronpa(弹丸论破)
    HDU 5813 Elegant Construction(优雅建造)
    HDU 5831 Rikka with Parenthesis II(六花与括号II)
    HDU 5810 Balls and Boxes(盒子与球)
    HDU 5818 Joint Stacks(联合栈)
    Dream Team(最小生成树)
    带权并查集
    HDU 1495 非常可乐(BFS)
    I Hate It(线段树+更新)
    Just a Hook(线段树+区间更新)
  • 原文地址:https://www.cnblogs.com/chy1000/p/6879850.html
Copyright © 2020-2023  润新知