php - Exception handling the right way -
i have rather simple question, read articles error , exception handling in php, have still questions left unawnsered.
1) in way make custom exception classes (that extend php's default exception)? , in cases should make custom exceptions?
2) read exceptions have caught catch/try block, see thrown exceptions in codes without try/catch blocks. using set_exception_handler() function? , how should use function properly?
3) allow custom behaviors when exception thrown (for example, record exceptions in database), should use set_exception_handler() or else?
thank taking time read questions , have nice day!
if need exceptions more built-in exceptions extending them way go. there not more that.
they not have to caught. should caught @ point (see 3.) if writing library or module of kind can throw exceptions , leave the user of code catch it.
you can wrap entire application in
try-catchblock , catch exceptions there, , need them (e.g. save them log file, or database matter).
i avoid using set_exception_handler (using 3. preferable, in opinion), in cases may good, or only, solution.
Comments
Post a Comment