Jump to content

Exception problems


moon 111

Recommended Posts

I'm totally new to exceptions in PHP, but aren't you supposed to throw exceptions yourself? E.g. with a function:

 

<?php
class someName {
//defined class
}
function validate($class) {
if (!class_exists($class)) {
	throw new Exception("Class \"$class\" doesn't exist.");
} else {
	echo 'Class "', $class, '" exists.<br />';
}
}
try {
validate('someName');
validate('NonexistentClass');
} catch(Exception $e) {
echo 'Error: ', $e->getMessage();
}
?>

 

Output:

Class "someName" exists.
Error: Class "NonexistentClass" doesn't exist.

 

In case I just don't get it yet, disregard what I said ;)

Link to comment
https://forums.phpfreaks.com/topic/102019-exception-problems/#findComment-522137
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.