I don't exactly know how exceptions work. as I assume, they should avoid php errors and display "my error message". for example, i want to open file
class File{
public $file;
public function __construct($file)
{
try{
$this->file = fopen($file,'r');
}
catch(Exception $e){
echo "some error" . $e->getMessage();
}
}
}
$file = new File('/var/www/html/OOP/texts.txt');
it works. now I intentionally change the file name texts.txt
to tex.txt
just to see an error message from my catch block, but instead, php gives an error Warning: fopen(/var/www/html/OOP/texts.txt): failed to open stream: No such file or directory in /var/www/html/OOP/file.php on line 169
. so it's php error, it doesn't display error message from catch block. What am I doing wrong? how exactly try/catch works?