what is the better way of generating an Exception Message?

129 views
Skip to first unread message

kavith Thiranga

unread,
Sep 27, 2012, 1:56:32 AM9/27/12
to joomla-de...@googlegroups.com
Hi all,

What is most preferred way of generating an exception? In a previous thread , I was told that JText shouldn't be used.

Thank you.

Elin Waring

unread,
Oct 1, 2012, 8:08:40 AM10/1/12
to joomla-de...@googlegroups.com

We're just using plain quoted text (you can't use JText because you can't count on it being available). You can use sprintf.  here's an example:

Elin

Donald Gilbert

unread,
Oct 1, 2012, 9:26:04 AM10/1/12
to joomla-de...@googlegroups.com
Why can't you count on JText being available? This is in the joomla platform, where JText IS available. If you're talking about for long term - are there plans to deprecate JText? If so, what is going to be used for translations of interface elements and language within the platform / cms?

Michael Babker

unread,
Oct 1, 2012, 9:28:57 AM10/1/12
to joomla-de...@googlegroups.com
The goal is to separate the packages to leave as few dependencies as possible.  If JText were used for all of the exceptions, then you would always require the Language package from the platform.  For the project you're building, you may not need it.

Michael Babker

unread,
Oct 1, 2012, 9:34:32 AM10/1/12
to joomla-de...@googlegroups.com
I guess a good example would be the upgrade check application I built to help check system requirements for CMS 3.0.  https://github.com/mbabker/J30UpgradeCheck/tree/master/libraries – Notice how there's a lot of folders missing from the cms, joomla, and legacy trees.  I removed everything that I didn't need to make this package as light-weight as possible.

Donald Gilbert

unread,
Oct 1, 2012, 9:42:08 AM10/1/12
to joomla-de...@googlegroups.com
Ok, but the point of a platform is how well the pieces work together. I can understand decoupling JText, since you may or may not need it if you use the platform for something besides the CMS, but what then are you going to use for translations?

How far does this goal reach? Removing all class inter-dependency within a development platform seems ludicrous to me, because it (very often) breaks the DRY principle.

Niels Braczek

unread,
Oct 1, 2012, 11:36:43 AM10/1/12
to joomla-de...@googlegroups.com
Am 01.10.2012 15:26, schrieb Donald Gilbert:

> Why can't you count on JText being available? This is in the joomla
> platform, where JText IS available.

*If* it is available. You can't rely on anything from the Framework or
CMS being working during Exceptions.

Regards,
Niels

--
| http://barcamp-wk.de · 2. Barcamp Westküste Frühjahr 2013 |
| http://www.bsds.de · BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
------------------------------------------------------------------

Michael Babker

unread,
Oct 1, 2012, 12:44:37 PM10/1/12
to joomla-de...@googlegroups.com
All of the exceptions were converted to static text.  This ensures that the message isn't dependent on a language string being available.  If my project doesn't need translations, then it's as simple as not including the Language package (if all other dependencies are broken from it).  If I need translations, I'll use the Language package and JText since it's a tested system and works.

As far as breaking all dependencies, I doubt it will happen.  But where other solutions are available, we're moving in that direction.  There's been a few commits to the Platform replacing calls to JFile::exists with PHP's native is_file, for example.  Some things are simple to replace, others need some work.  In the end though, I think it will improve the overall code quality of the Platform.

From: Donald Gilbert <dilber...@gmail.com>
Reply-To: <joomla-de...@googlegroups.com>
Date: Monday, October 1, 2012 8:42 AM
To: <joomla-de...@googlegroups.com>
Subject: Re: [jplatform] Re: what is the better way of generating an Exception Message?

Louis Landry

unread,
Oct 1, 2012, 1:11:04 PM10/1/12
to joomla-de...@googlegroups.com
Just to follow up on what Niels and Michael have said here, the direction is not to copy/paste code all over the place un-DRY-ing everything.  The idea is that separate parts should be separate.  Quite a bit of the platform was written to bridge gaps in PHP.  Either bridging from PHP4 to PHP5 (eg. JObject, JSimpleXML) or just filling in things we found as holes here and there.  In a few places we tried to bridge the gap between PHP installations such as JFTP, which is designed to use the native FTP methods if present and fall back on our own implementation if they are not present.  Not all hosts have the FTP extension installed, and we felt it was necessary at the time to make things less painful for lots of new users.  As these things become less necessary we will re-evaluate their lease on life.

With respect to Exception messages, I am strongly against having translation within those messages.  The reality of the situation is that exception messages are for developers, not users.  A well built application will catch exceptions, inspect them, and then either direct or message the user gracefully.  As pointed out we don't know if the exception may have occurred within the mechanism to translate the message, or some dependency of that translation mechanism.  As a project we are certainly committed to internationalization and localization, but I don't see the reward vs the risk on translating exception messages ... especially at the point where they are thrown.

Lastly, with respect to separation of platform packages, this is something we want to work towards.  It isn't an absolute, but it is a principle.  Similarly, DRY is a principle.  Sometimes it is just insane not to repeat a block of code somewhere else.  Other times it is insane to do so.  One of our goals is to build the platform in such a way that we can only select the packages we actually need for a project.  We'll continue to work towards that end, and also continue to work towards not repeating ourselves.  When those two principles conflict we will have to assess, make a judgement call, and move forwards.

I hope that helps.

- Louis

Donald Gilbert

unread,
Oct 1, 2012, 1:23:46 PM10/1/12
to joomla-de...@googlegroups.com
That helps a lot actually. Thanks for clarifying.

This may be a discussion for another thread, as we (I) kind of hijacked the thread, but the question has been answered, so that's good.

kavith Thiranga

unread,
Oct 2, 2012, 3:13:25 AM10/2/12
to joomla-de...@googlegroups.com
hi all,

Got the answer with some great explanations. Thank you all.


On Mon, Oct 1, 2012 at 10:53 PM, Donald Gilbert <dilber...@gmail.com> wrote:
That helps a lot actually. Thanks for clarifying.

This may be a discussion for another thread, as we (I) kind of hijacked the thread, but the question has been answered, so that's good.




--
Kavith Thiranga Lokuhewage,
Undergraduate,
BSc (Hons) Software Engineering,
Staffordshire University, UK.

JM Simonet

unread,
Oct 5, 2012, 4:31:05 AM10/5/12
to joomla-de...@googlegroups.com
I have no issue with not translating Exception messages.
What would be handy though is to get regularly the list of JLIB strings we can safely take off from the .ini files.
This would greatly help new Transators as they would not have to translate these.

JM
-- 
Please keep the Subject wording in your answers
This e-mail and any attachments may be confidential. You must not disclose or use the information contained in this e-mail if you are not the
intended recipient. If you have received this e-mail in error, please notify us immediately and delete the e-mail and all copies.
-----------------------------------------------------------
Jean-Marie Simonet  /  infograf768
Joomla Production Working group
Joomla! Translation Coordination Team 
Reply all
Reply to author
Forward
0 new messages