Exception Handling

FnPub interface functions can report fatal error conditions to callers by using C++ exception-handling. There is a new exception base class, MAXException, defined in iFnPub.h that can be thrown directly, or subclassed as needed for error grouping. The class is defined as follows:

class MAXException
{
   public:
     TSTR message;
     int error_code;
     MAXException(TCHAR* msg, intcode=0)
       : message(msg), error_code(code) { }
};

It contains a message buffer and an optional error code. You would signal an error using the MAXException() constructor and the C++ throw statement, as in the following example:

if (discrim < 0.0) // oh-oh, not good
   throwMAXException ("Unableto findroot.", -23);

This signals a fatal error with the message and code shown. If the error occurs during a call to the function by MAXScript code, it will be trapped by MAXScript and the error message will be displayed and the running script will be terminated (but 3ds Max will continue running). If the error occurs during a C++-level call, typically the outer 3ds Max error catcher will catch and report the error and then exit 3ds Max, or clients of the interface can install their own catch code.