Exceptions
When an error occurs, the IMu .Net API throws an exception. The exception is
an IMuException object. This is a subclass of .Net's standard
ApplicationException class.
For simple error handling all that is usually required is to catch the exception and report the exception as a string:
try
{
// ⋯
}
catch (IMuException e)
{
Console.WriteLine("Error: {0}", e);
}
The IMuException class overrides the Exception class's ToString
method and returns an error message.
To handle specific IMu errors it is necessary to check the exception is an
IMuException object before using it. The IMuException class
includes a property called id. This is a string and contains the internal
IMu error code for the exception. For example, you may want to catch the
exception raised when a Session object's Connect method fails and
try to connect to an alternative server:
String mainServer = "server1.com"; String alternativeServer = "server2.com"; Session session = new Session(); session.Host = mainServer;try { session.Connect(); }catch (IMuException e) { // Check for specific SessionConnect errorif (e.ID != "SessionConnect") { Console.WriteLine("Error: {0}", e); return; } session.Host = alternativeServer; try { session.Connect(); } catch (Exception e) { Console.WriteLine("Error: {0}", e); return; } } /* * By the time we get to here the session is connected to either the main * server or the alternative. */

