Notice: Undefined index: in /data/phpspider/phplib/misc.function.php on line 226
JSP EL自定义函数中的异常处理实践_Jsp_Function_Exception Handling_Taglib - Fatal编程技术网

JSP EL自定义函数中的异常处理实践

JSP EL自定义函数中的异常处理实践,jsp,function,exception-handling,taglib,Jsp,Function,Exception Handling,Taglib,我已经定义了一个用于包装的,但不确定如何处理所有选中的异常 具体来说,我的问题是:如何解决代码中的TODO public static String toJSON(Object o) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(o); } catch (JsonGenerationException e) { // TO

我已经定义了一个用于包装的,但不确定如何处理所有选中的异常

具体来说,我的问题是:如何解决代码中的TODO

public static String toJSON(Object o) {
    ObjectMapper mapper = new ObjectMapper();
    try {
        return mapper.writeValueAsString(o);
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}
匹配的标记库当前为:

<function>
    <description>Converts an object to JSON</description>
    <name>toJSON</name>
    <function-class>uk.co.ondemand.whitelabel.taglibs.ScriptingFunctions</function-class>
    <function-signature>java.lang.String toJSON(java.lang.Object)</function-signature>
    <example>
      var theAsset = ${wls:toJSON(asset)};
    </example>
</function>

将对象转换为JSON
toJSON
uk.co.ondemand.whitelabel.taglibs.ScriptingFunctions
java.lang.String toJSON(java.lang.Object)
var theAsset=${wls:toJSON(资产)};

只需在方法的
throws
子句中声明它们,直到您知道如何/在何处处理它们

public static String toJSON(Object o) throws IOException {
    return new ObjectMapper().writeValueAsString(o);
}

是否有一些资源讨论了我可以在哪里处理它们(在自定义JSP标记处理程序的特定上下文中)?如果您希望对最终用户更友好一点并关注日志,请在
web.xml
中定义
。这些错误是开发人员的错误,而不是最终用户的错误。