Part of the problem of following a discussion on changes to JException and JError is, I believe, a difference in viewpoint.
From the point of view of developing platform code, when an exception is to be thrown that's it, end of the line, abort everything and die. Provide enough information in the exception for debugging and DIE.
And due to the beauty of Object Oriented Programming and the exception object - throwing the exception is literally all you need. You don't even need to set a message. You don't need to subclass it. Just throw it.
Does a developer want to know what class caused the exception? getFile and getLine tells you exactly what file is the cause of the problem and therefore what class.
Do you want exhaustive information? getTrace gives you that.
Is it possible that this exception was triggered by another exception? Now a problem since if you coded it correctly, then you called 'throw Exception('',$previousException)' and so a call to getPrevious gives that information.
The confusion for me is that when working on a component or module, there may well be error conditions which should NOT terminate the program. For example, a module to grab the latest stock price every 15 minutes from Google Finance, cache it and display it. Lots of failure points here:
Unable to grab the latest price: just use the last retrieved price
Unable to cache the data, just display what was retrieved
Unable to grab the latest price AND nothing in the cache: don't display anything
In none of these cases would a site owner want the entire application to die. It's better to display everything BUT that snippet than to display nothing.
So what SHOULD be done with these? Well, an Exception should still be thrown, but in this case the Exception be handled and move on.
From a developer standpoint, to handle this when the framework does not provide it, I should not ever throw a bare Exception. Instead I should subclass exception:
class GaryException extend Exception {}
Now I can add a custom catcher to just process GaryExceptions. During development I may want to die at that point and display some good data. During deployment instead I'll want to notify something internally of the error and keep running.
Now suddenly I have a use for 'codes'. I might want to classify my exceptions into:
critical, must be looked at right away
error, module or component had to abort
warning, module or component is not functioning properly
info, temporary issue
In my example, not getting a stock price from google due to a network timeout is informational, network hiccups happen, life goes on. Not being able to cache the data is a warning because it indicates an underlying issue. An error might be if using a paid stock ticker api, an invalid userid and password - since that needs to be fixed.
Now, I could use subclasses but that means giving up a lot of PHP's built in functionality or is extremely messy.
If I give up SPL functionality, then I can implement:
CriticalGaryException, ErrorGaryException, WarningGaryException, InfoGaryException
And I am done.
But if I want SPL functionality, I will also need to define a Gary...Exception for all the SPL exceptions(13 of them at the moment) and 4 state levels for each one.
So what an end developer using the Joomla Platform really needs is:
JPlatformException extends Exception and to be nice 13 subclasses such as
JPlatform BadFunctionCallException extends
JPlatform Exception
Note: I chose JPlatform instead of the traditional JException since there already IS a JException class.
We don't need any codes defined for us since the decision for what to do with different levels of exceptions is something that is dependant on the implementation of the platform, not on the platform itself.
Ideally, there should be follow through on the CMS side to define some codes, JCMSException::CRITICAL, JCMSException::WARNING, JCMSException::ERROR, JCMSException::INFO as well as a plugin configured which can catch all JExceptions[and thus all children of JPlatformException], check the code and either die with the error.php template as it does now or send the exception data to JLog. This plugin can be configured for what level of exceptions to log and which to abort on.
Then it would be up to each component/application developer. They can use the built in exceptions, or subclass them for yet more application specific uses. Personally, I would like to see each developer subclass them to their company/group name. Ie myCompanyException extends JCMSException. In that manner, if the error is ever displayed on the website, it provides a clue on whether the problem is in the Platform, the CMS, or in 3rd party code[and if in 3rd party, who the heck to blame!]
As it is right now, with a single error/exception mechanism, it is being used for multiple purposes which leads to confusion. Core developers don't see a point to all the extra intelligence because when they use it they only want to do one thing: die. And application developers tend to avoid using exceptions because the impact of how they are used is a showstopper.
If this appears right to others, I'm willing to go ahead and submit a patchfile. The beauty of this approach is that it's really not that much work since I'm not adding any functionality to the exceptions themselves, just creating 14 subclasses and unit tests for those 14 subclasses. Document what the purpose of the classes are and how they can be used. The only functional change would be in JException itself where whenever it currently throws an Exception it now should throw a JPlatformException.