Tutorial 7: Implementing the JSAPI to catch exceptions with an error callback function
This tutorial provides step-by-step instructions for authoring a web page to catch exceptions and test them by generating a specific error to trigger the exception handler. Write an errorHandler function to catch exceptions in a web page.
1 Using a code editor, open or create a BasicViewer.html file that contains a basic implementation of the viewer.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<title>Basic Viewer Example</title>
<body onload="init( )">
<tr><td class="jsapi_example_label">Report File:<td colspan="4">
<input type="text" size="80" id="reportfile" value=
"/Applications/BIRT Sample App/Customer Dashboard.rptdesign" name="Report_name">
<tr><td><input type="button" class="btn" id="run"
value="Run Viewer" onclick="run()" disabled="true">
<div id="content">
<script type="text/javascript" language="JavaScript" src=""></script>
<script type="text/javascript" language="JavaScript">
var viewer;
function init( ) {
actuate.initialize( "", null, null, null, initViewer);
function initViewer( ) {
viewer = new actuate.Viewer("content");
document.getElementById("run").disabled = false;
function run(){
viewer.setReportName(document.getElementById( "reportfile" ).value);
<!-- write an event handler to catch exceptions -->
For more information about implementing the JSAPI viewer, see Viewing reports.
2 Navigate to the following line:
<!-- write an event handler to catch exceptions -->
Replace the line with the following code:
function errorHandler(exception){
alert("Your application encountered an exception: \n" + exception.getMessage());
3 Navigate to the following line:
actuate.initialize( "", null, null, null, initViewer);
Add errorHandler to the parameter list as the optional exception handler for initialize, as shown in the following code:
actuate.initialize( "", null, null, null, initViewer, errorHandler);
4 Save the file as basicexception.html.
5 In Internet Explorer, open basicexception.html.
If you receive a security warning that Internet Explorer has restricted this page from running scripts or ActiveX controls that could access your computer, right-click on the message and select Allow Blocked Content.
6 Open basicexception.html. The errorHandler function runs because no login credentials have been provided, as shown in Figure 16‑3.
Figure 22-16 Chart showing a ToolTipFigure 22-16 Chart showing a ToolTip
Figure 16‑3 Authentication message from errorHandler