There is a StatusService for each Application that does exactly what is suggested, it catches any Throwable (Exception and Errors), logs the exception and sets the status to InternalError. It is implemented as a filter in the NRE.
As Resource.getVariants() doesn't declare any exception, it may be necessary to wrap your JSONException into a RuntimeException. Is that an issue? Best regards, Jerome > -----Message d'origine----- > De : news [mailto:[EMAIL PROTECTED] De la part de Justin C. > van Vorst > Envoyé : jeudi 16 novembre 2006 03:37 > À : [email protected] > Objet : Re: how to return 500 server error upon exception > > David Choi <daft.davy <at> gmail.com> writes: > > > > > Hello, > > > > When constructing DOM documents to create DOM > Representations (or, for that > > matter, JSON Objects for JSONRepresentations), I need to > return a 500 Internal > > Server Error when DOM Document/JSON Object creation throws > an exception. > > > > For example: > > JSONObject jObj = new JSONObject(); > > try > > { > > jObj.put("blah", blah); > > ... > > } > > catch(JSONException e) > > { > > //something needed here? > > } > > > > What is the best way to do this? Currently, if the > exception occurs, I just > > skip adding the representation to the list of variants returned by > > getVariants(), but this returns a 404 - Resource Not Found. > > > > Thanks, > > David > > > > > > > > Why not simply create a Fiter that has a try/catch block in > the doHandle() > method? The try block would simply pass control to the next > Restlet, and if > somewhere downstream a Handler throws a particular unchecked > exception, the > filter will do the proper handling. This of course assumes a > downstream restlet > isn't arbitrarily catching unexpected Throwables (which > probably isn't a good > idea anyway).

