List of usage examples for java.lang InstantiationException fillInStackTrace
public synchronized Throwable fillInStackTrace()
From source file:com.ecyrd.jspwiki.plugin.PluginManager.java
/** * Executes a plugin class in the given context. * <P>Used to be private, but is public since 1.9.21. * * @param context The current WikiContext. * @param classname The name of the class. Can also be a * shortened version without the package name, since the class name is searched from the * package search path./*from ww w .java2 s.c o m*/ * * @param params A parsed map of key-value pairs. * * @return Whatever the plugin returns. * * @throws PluginException If the plugin execution failed for * some reason. * * @since 2.0 */ public String execute(WikiContext context, String classname, Map params) throws PluginException { if (!m_pluginsEnabled) return ""; ResourceBundle rb = context.getBundle(WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE); Object[] args = { classname }; try { WikiPlugin plugin; boolean debug = TextUtil.isPositive((String) params.get(PARAM_DEBUG)); WikiPluginInfo pluginInfo = m_pluginClassMap.get(classname); if (pluginInfo == null) { pluginInfo = WikiPluginInfo.newInstance(findPluginClass(classname)); registerPlugin(pluginInfo); } if (!checkCompatibility(pluginInfo)) { String msg = "Plugin '" + pluginInfo.getName() + "' not compatible with this version of JSPWiki"; log.info(msg); return msg; } // // Create... // try { plugin = pluginInfo.newPluginInstance(); } catch (InstantiationException e) { throw new PluginException( MessageFormat.format(rb.getString("plugin.error.cannotinstantiate"), args), e); } catch (IllegalAccessException e) { throw new PluginException(MessageFormat.format(rb.getString("plugin.error.notallowed"), args), e); } catch (Exception e) { throw new PluginException( MessageFormat.format(rb.getString("plugin.error.instantationfailed"), args), e); } // // ...and launch. // try { return plugin.execute(context, params); } catch (PluginException e) { if (debug) { return stackTrace(params, e); } // Just pass this exception onward. throw (PluginException) e.fillInStackTrace(); } catch (Throwable t) { // But all others get captured here. log.info("Plugin failed while executing:", t); if (debug) { return stackTrace(params, t); } throw new PluginException(rb.getString("plugin.error.failed"), t); } } catch (ClassNotFoundException e) { throw new PluginException(MessageFormat.format(rb.getString("plugin.error.couldnotfind"), args), e); } catch (ClassCastException e) { throw new PluginException(MessageFormat.format(rb.getString("plugin.error.notawikiplugin"), args), e); } }