Custom Exception Messages: Best practices

前端 未结 5 1716
無奈伤痛
無奈伤痛 2020-12-22 17:27

Wondering how much effort I should go to forcing useful debugging information when creating exception messages, or should I just trust the user to supply the right info, or

5条回答
  •  死守一世寂寞
    2020-12-22 17:50

    I won't detract from the advise regarding Krzysztof's blog, but here is a dead-easy way to create custom exceptions.

    Example:

    
    

    The code behind that (which I borrowed somewhere, apologies to whomever that was)

    message}' in {$this->file}({$this->line})\n"
                                    . "{$this->getTraceAsString()}";
        }
    }
    

提交回复
热议问题