Question: mkdir() is working correctly this question is more about catching an error. Instead of printing this when the directory exists I would just like to have it write to a message to me in a custom log. How do I create this exception.

Warning: mkdir() [function.mkdir]: File exists

Answer: 
> 
> I would just like to have it write to a message to me in a custom log.
> 
> 
> 

the solution is very easy. PHP already have everything for you:

```
ini_set('display_errors',0);
ini_set('log_errors',1);
ini_set('error_log','/path/to/custom.log');

```

or same settings in the php.ini or .htaccess  

I think it would be better than write each possible error manually 

If you don't want this error to be logged (as it may be not error but part of application logic), you can check folder existence first

```
if (!file_exists($folder)) mkdir($folder);
else {/*take some appropriate action*/}

```
You can rewrite any system call function with a class like this:

`file: system.php`

```
namespace abc;

class System {

    const CAN_NOT_MAKE_DIRECTORY = 1;

    static public function makeDirectory($path) {
        $cmd = "mkdir " . $path;
        $output = \shell_exec($cmd . " 2>&1"); // system call
        if ($output != "") {
            throw new \Exception($output, System::CAN_NOT_MAKE_DIRECTORY);
        }
        return(\TRUE);
    }

}

```

Then you can call the method and intercept the exception:

`file: index.php`

```
namespace abc;
require 'system.php';

try {
    System::makeDirectory($directoryName);
} catch (\Exception $e) {
    throw new \Exception($e->getMessage(), System::CAN_NOT_MAKE_DIRECTORY);
} 

```

Now you can treat all the system errors with the `try {...} catch(...) {...} finally {...}` normally.