PrevNextUpHome SophiaFramework UNIVERSE 5.3

6.3. Error Handling

In SophiaFramework UNIVERSE, the pseudo catch-throw syntax like the exception handling syntax in standard C ++ is used for error handling as follows:

The type of error value is SFCError.

Function Description
static_catch Catch the error.
static_try Check whether or not an error has occurred.
static_throw Set the error.
static_throws Indicate that the function may throw an error.(no precessing will be do)
[Note] static_throws macro

The static_throws macro, which is described at the end of member function declaration, indicates to the developer that the function may throw an error.

Since the static_throws macro will be deleted at compile time, there will be no influence at run time if it is omitted.

In Visual C++ 6.0, there is a possibility that a class list may not be displayed in ClassView if this macro is used.

In such a case, to display a class list in ClassView, you have to delete this macro or describe the below at the head of your header file.

#define static_throws

Example 6.1. Error handling

class MyApp : public SFCApplication {
  public:
    Void SubFunc(Void) static_throws;  // <- SubFunc may throw an error
                                       // static_throws indicates the action above
    Void MainFunc(Void);
    ...
};

Void SubFunc(Void) static_throws       // <- SubFunc may throw an error
                                       // static_throws indicates the action above
{
    // checks whether or not an error has occurred
    if (static_try()) {  
        // when there is no error

        // create an object
        XXXObjectPtr object = new XXXObject();
        if (object == null) { 
            // when it fails to create the object

            static_throw(SFERR_NO_MEMORY);  // throw the SFERR_NO_MEMORY error
                                            // SFERR_NO_MEMORY: out of memory

            return; // static_throw will not return automatically
                    // therefore you have to return manually
        }
    }

    ...
}

Void MainFunc(Void)
{
    ...
    SubFunc();
    switch (static_catch()) {
        // error handling for various errors

        case SFERR_NO_MEMORY: // when "out of memory" has occured

            ...

        case SFERR_NO_ERROR:  // when no error has occurred

            ...
    }

    ...
}