Error Handling When Loading Pages

If an un-caught exception is thrown when loading a ZUML page, it is handled directly by the Web server. In other words, its handling is no different from other pages, such as JSP.

By default, the Web server displays an error page showing the error message and stack trace.

You can customize the error handling by specifying the error page in WEB-INF/web.xml as follows. Refer to Java Servlet Specification for more details.

<!-- web.xml -->
<error-page>
    <exception-type>java.lang.Throwable</exception-type>    
    <location>/WEB-INF/sys/error.zul</location>    
</error-page>

Then, when an error occurs in loading a page, the Web server forwards the error page you specified, /error/error.zul. Upon forwarding, the Web server passes a set of request attributes to the error page to describe what happens. These attributes are as follows.

Request Attribute

Type

javax.servlet.error.status_code

java.lang.Integer

javax.servlet.error.exception_type

java.lang.Class

javax.servlet.error.message

java.lang.String

javax.servlet.error.exception

java.lang.Throwable

javax.servlet.error.request_uri

java.lang.String

javax.servlet.error.servlet_name

java.lang.String

Then, in the error page, you can display your custom information by use of these attributes. For example,

<window title="Error ${requestScope['javax.servlet.error.status_code']}">
    Cause: ${requestScope['javax.servlet.error.message']}    
</window>

Tip: The error page can be any kind of servlets. In addition to ZUL, you can use JSP or whatever you preferred.

Tip: After forwarded, the error page is displayed as the main page, so you don't need to specify the modal or overlapped mode for the main window, if any.

ZK Mobile Error Handling

Servlet 2.x (web.xml) doesn't have the concept of device types. Thus, you have to forward to correct page if you want to support the Ajax browser and mobile devices at the same server. Here is an example:

//error.zul
<zk>
    <zscript>    
    if (Executions.getCurrent().isMilDevice())    
        Executions.forward("error.mil");        
    </zscript>    
    <window>    
    ....error message in ZUL    
    </window>    
</zk>