Architecture - Exceptions

All exceptions discussed below are collected in the agent and can be viewed in the MIB browser. This collection is lost after agent cold restart.

Identical exceptions are preserved as a single instance with a counter. Exceptions are considered identical if their full stack traces are identical. This approach consumes less memory for repeated exceptions.

Application Exceptions
FriendlySNMP agent provides convenient API to report to the MIB browser exceptions discovered in the application:

public void reportException(String comment, Throwable e)

This method is available in the agent object and each MIB registered with the agent. Reported exception triggers notification appExceptionCaught declared in the FRIENDLY-SNMP-MIB.

See below how to view all collected exceptions in the MIB browser.

Unchecked Exceptions
FriendlySNMP agent provides handling unchecked exceptions using techniques discussed in the following documentation:

  • (since Java 1.1) in JavaDoc for the method handleException() in the class java.awt.EventDispatchThread. Note, this class has package access and it is not visible in Java API, go to the source code.
  • (since Java 1.5) in JavaDoc Thread.UncaughtExceptionHandler.

The agent has configuration option to show or hide unchecked exception stack traces in the console.

The application may register org.friendlysnmp.event.UncaughtExceptionListener with the agent to receive uncaught exceptions events. This event could be used by GUI application to display popup window with discovered exception.

Discovered unchecked exception triggers notification appExceptionUncaught declared in the FRIENDLY-SNMP-MIB.

See below how to view all collected exceptions in the MIB browser.

Agent Exceptions
All exceptions which are related to the agent are thrown as org.friendlysnmp.FException. The exception thrown may include a cause exception if available.

The agent exceptions could be thrown in a buggy agent code or in registered listeners. Very often the exception cause is an error in value conversion when a value type is modified at the development time.

Usually catching exceptions in registered listeners and in the agent code itself becomes an annoying process of endless repeats of try/catch blocks. In most cases a developer's single option to handle an exception is to log it. This gives very little value for the application.

The FriendlySNMP provides a no throw alternative for many mostly often used methods, for example:

public void setValue(Object obj) throws FException
public void setValueEx(Object obj)
The methods with name suffix Ex do not throw exception but forwards it to the agent. The agent reports the exception to the MIB browser via notification and to all registered org.friendlysnmp.event.FExceptionListener listeners via Java event. The application may handle the exception in many ways. For example, a GUI application may display a popup message with this exception. A server application may store it in an exceptions log.

Viewing Exceptions
Exceptions could be viewed in the MIB browser as a list of all exceptions or one by one with full stack trace.

The table exceptionsListTable contains a full list of exceptions. Example of this table for three exceptions was generated in a demo application:

The column Thread with thread name where the exception occur and the column Action are not visible in this image at the right. The value in the column Count is incremented each time an exception with identical stack trace is caught. The column Action allows to delete a row from a table.

The table exceptionViewTable contains details for each exception. Example of this table for one of exceptions from the example above:

The table contains full stack trace of one of the exceptions. The cause exceptions with their full stack trace are included if they exist.

There are two methods next and fixed to navigate through exceptions. The choice of the navigation method is defined in the read-write scalar exceptionViewPolicy.

Method next
Refresh the table to load next exception details.

Method fixed
Specify the index of the exception in the read-write scalar exceptionViewFixedIndex and refresh the table to view the specified exception details.