【问题标题】:Best SPL Exception for file errors in PHPPHP 中文件错误的最佳 SPL 异常
【发布时间】:2016-06-01 14:20:00
【问题描述】:

我想检查某个目录是否可写(应该是),如果不是,则抛出这样的技术异常:

if (!is_writable($new_dir)) {
  throw new SomeSPLException ("Bad!");
}

什么类型的标准 PHP SPL 异常最适合这种情况?

【问题讨论】:

    标签: php file exception exception-handling spl


    【解决方案1】:

    查看内置异常后

    http://php.net/manual/en/spl.exceptions.phphttp://php.net/manual/en/reserved.exceptions.php

    我会亲自创建自己的,因为似乎没有一个真正适合

    class NonWritableDirectoryException extends \Exception {}
    

    或者也许......再看一眼......我会去RuntimeException并传递诸如“不可写目录”之类的消息,尽管我仍然认为第一个想法是要走的路

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-02
      • 2011-01-25
      • 1970-01-01
      • 2010-12-15
      • 2010-10-24
      • 1970-01-01
      • 2018-08-08
      相关资源
      最近更新 更多