It would be done using Commons Lang's ExceptionUtils class:
- script services should never throw exceptions
- instead they should return null (or empty string, etc)
- they should store the exception in the execution context and provide an API to access the exception
- it's up to the caller (*.vm files, wiki pages) to decide what to do when there's an error.
- In some *.vm files we need to display the error and being able to use $exceptiontool.getStackTrace($myscriptservice.lastError) would be nice. Otherwise it forces all script services to offer an API to transform an Exception into a String. In addition ExceptionUtils offers other interesting methods, such as getting the root cause, etc.
XWIKI-11050 Do not fail the UI when there's a problem rendering the document's content