How to interpret $code
depends on the exception type. For example, if you have a Exception
subclass that represents a MySQL database error, then $code
might be the native MySQL error code. In the case of low-level IO errors, this may be the value from <errno.h>
.
Basically, $code
should contain what you need to handle the exception programmatically. Most exceptions should be handled somewhere. If all your exceptions just show up as errors, then $code
is only useful if you need to include error codes from something like a MySQL client library.
This message is for display to the user, while the code is for your program to use. So for example, in your "Database Error" example, you could write a set of code like this:
Then use the corresponding code. When other parts of the code encounter an exception, they will know what happened and may be able to handle it intelligently.