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!

  1. if need exceptions more built-in exceptions extending them way go. there not more that.

  2. 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.

  3. you can wrap entire application in try-catch block , 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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -