I would like to catch some exceptions to inspect the error code and determine if I should re-throw it with a more user friendly message. This would probably be most beneficial with MySQL errors. Is there a file of defined constants I could leverage for use in my component? Or, does everyone just hard-code the numeric value and/or create their own constants?
You should use Exceptions to handle the error and your message.
If you are supporting both J2.5 and J3.x+ you can handle the error on a per-version case.
if (JError::$legacy) {
// Use legacy error handling
} else {
// Use PHP exception handling
}
here is an example from the CMS of the kind of thing your trying to do.
If PHP has a built-in exception handler, then that's used. Otherwise if a developer has created something to handle exceptions, that's used.
If you're unhappy with an existing exception handler, you can always extend it to make it more robust.
-
Thank you for the assistance but I wasn't asking about exception handling. I was asking about error codes. Is there a file(s) that can be included to define errors such as 1062 (duplicate entry). I prefer to use a constant such as ER_DUP_ENTRY in code as opposed to using the numeric value itself (it's more readable). – nimble Apr 26 '16 at 20:43
in your template directory, there is a file error.php that you can modified to show more appropriate info on your errors.