tdf#120703 PVS: dereference before nullptr check

Use a function to consistently check if gImpl is valid before assigning last
exception message.

V595 The 'gImpl' pointer was utilized before it was verified against nullptr.
     Check lines: 2673, 2683.

Change-Id: I18fc0d632c84f37b05e9d1c3c83689e6eaa6f66c
Reviewed-on: https://gerrit.libreoffice.org/71488
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 9373313..497c31b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -163,6 +163,12 @@
static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
static std::weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;

static void SetLastExceptionMsg(const OUString& s = OUString())
{
    if (gImpl)
        gImpl->maLastExceptionMsg = s;
}

struct ExtensionMap
{
    const char *extn;
@@ -1872,8 +1878,7 @@
    comphelper::ProfileZone aZone("doc_saveAs");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);

@@ -1881,7 +1886,7 @@
    OUString aURL(getAbsoluteURL(sUrl));
    if (aURL.isEmpty())
    {
        gImpl->maLastExceptionMsg = "Filename to save to was not provided.";
        SetLastExceptionMsg("Filename to save to was not provided.");
        SAL_INFO("lok", "URL for save is empty");
        return false;
    }
@@ -1920,7 +1925,7 @@
            }
            else
            {
                gImpl->maLastExceptionMsg = "input filename without a suffix";
                SetLastExceptionMsg("input filename without a suffix");
                return false;
            }
        }
@@ -1936,7 +1941,7 @@
        }
        if (aFilterName.isEmpty())
        {
            gImpl->maLastExceptionMsg = "no output filter found for provided suffix";
            SetLastExceptionMsg("no output filter found for provided suffix");
            return false;
        }

@@ -2016,7 +2021,7 @@
    }
    catch (const uno::Exception& exception)
    {
        gImpl->maLastExceptionMsg = "exception: " + exception.Message;
        SetLastExceptionMsg("exception: " + exception.Message);
    }
    return false;
}
@@ -2024,8 +2029,7 @@
static void doc_iniUnoCommands ()
{
    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    OUString sUnoCommands[] =
    {
@@ -2173,8 +2177,7 @@
    comphelper::ProfileZone aZone("doc_getDocumentType");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);

@@ -2200,12 +2203,12 @@
        }
        else
        {
            gImpl->maLastExceptionMsg = "unknown document type";
            SetLastExceptionMsg("unknown document type");
        }
    }
    catch (const uno::Exception& exception)
    {
        gImpl->maLastExceptionMsg = "exception: " + exception.Message;
        SetLastExceptionMsg("exception: " + exception.Message);
    }
    return LOK_DOCTYPE_OTHER;
}
@@ -2219,7 +2222,7 @@
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return 0;
    }

@@ -2231,13 +2234,12 @@
    comphelper::ProfileZone aZone("doc_getPart");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return 0;
    }

@@ -2249,13 +2251,12 @@
    comphelper::ProfileZone aZone("doc_setPart");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -2270,7 +2271,7 @@
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }

@@ -2288,13 +2289,12 @@
    comphelper::ProfileZone aZone("doc_getPartPageRectangles");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }

@@ -2312,13 +2312,12 @@
    comphelper::ProfileZone aZone("doc_getPartName");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }

@@ -2336,13 +2335,12 @@
    comphelper::ProfileZone aZone("doc_getPartHash");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }

@@ -2361,13 +2359,12 @@
    comphelper::ProfileZone aZone("doc_setPartMode");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -2411,8 +2408,7 @@
    comphelper::ProfileZone aZone("doc_paintTile");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SAL_INFO( "lok.tiledrendering", "paintTile: painting [" << nTileWidth << "x" << nTileHeight <<
              "]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
@@ -2421,7 +2417,7 @@
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -2506,8 +2502,7 @@
                                     const int nTileWidth, const int nTileHeight)
{
    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SAL_INFO( "lok.tiledrendering", "paintTileToCGContext: painting [" << nTileWidth << "x" << nTileHeight <<
              "]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
@@ -2516,7 +2511,7 @@
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -2546,8 +2541,7 @@
    comphelper::ProfileZone aZone("doc_paintPartTile");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SAL_INFO( "lok.tiledrendering", "paintPartTile: painting @ " << nPart << " ["
               << nTileWidth << "x" << nTileHeight << "]@("
@@ -2631,8 +2625,7 @@

static int doc_getTileMode(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis*/)
{
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();
    return LOK_TILEMODE_BGRA;
}

@@ -2643,8 +2636,7 @@
    comphelper::ProfileZone aZone("doc_getDocumentSize");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (pDoc)
@@ -2655,7 +2647,7 @@
    }
    else
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
    }
}

@@ -2665,8 +2657,7 @@
    comphelper::ProfileZone aZone("doc_initializeForRendering");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (pDoc)
@@ -2682,8 +2673,7 @@
                                 void* pData)
{
    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);

@@ -2737,12 +2727,11 @@
/// Returns the JSON representation of all the comments in the document
static char* getPostIts(LibreOfficeKitDocument* pThis)
{
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }
    OUString aComments = pDoc->getPostIts();
@@ -2752,12 +2741,11 @@
/// Returns the JSON representation of the positions of all the comments in the document
static char* getPostItsPos(LibreOfficeKitDocument* pThis)
{
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }
    OUString aComments = pDoc->getPostItsPos();
@@ -2766,12 +2754,11 @@

static char* getRulerState(LibreOfficeKitDocument* pThis)
{
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }
    OUString state = pDoc->getRulerState();
@@ -2783,13 +2770,12 @@
    comphelper::ProfileZone aZone("doc_postKeyEvent");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -2807,7 +2793,7 @@
        ITiledRenderable* pDoc = getTiledRenderable(pThis);
        if (!pDoc)
        {
            gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
            SetLastExceptionMsg("Document doesn't support tiled rendering");
            return;
        }
        pWindow = pDoc->getDocWindow();
@@ -2819,7 +2805,7 @@

    if (!pWindow)
    {
        gImpl->maLastExceptionMsg = "No window found for window id: " + OUString::number(nWindowId);
        SetLastExceptionMsg("No window found for window id: " + OUString::number(nWindowId));
        return;
    }

@@ -2843,13 +2829,12 @@
    comphelper::ProfileZone aZone("doc_postWindowKeyEvent");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
    if (!pWindow)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
        SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
        return;
    }

@@ -2874,8 +2859,7 @@
    comphelper::ProfileZone aZone("doc_renderShapeSelection");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    LokChartHelper aChartHelper(SfxViewShell::Current());

@@ -2925,8 +2909,7 @@
    catch (const uno::Exception& exception)
    {
        css::uno::Any exAny( cppu::getCaughtException() );
        if (gImpl)
            gImpl->maLastExceptionMsg = exception.Message;
        SetLastExceptionMsg(exception.Message);
        SAL_WARN("lok", "Failed to render shape selection: " << exceptionToString(exAny));
    }

@@ -2980,8 +2963,7 @@
    comphelper::ProfileZone aZone("doc_postUnoCommand");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SfxObjectShell* pDocSh = SfxObjectShell::Current();
    OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
@@ -3052,7 +3034,7 @@

    if (!bResult)
    {
        gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
        SetLastExceptionMsg("Failed to dispatch the .uno: command");
    }
}

@@ -3061,13 +3043,12 @@
    comphelper::ProfileZone aZone("doc_postMouseEvent");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3079,13 +3060,12 @@
    comphelper::ProfileZone aZone("doc_postWindowMouseEvent");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
    if (!pWindow)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
        SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
        return;
    }

@@ -3119,13 +3099,12 @@
    comphelper::ProfileZone aZone("doc_postWindowGestureEvent");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
    if (!pWindow)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
        SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
        return;
    }

@@ -3158,13 +3137,12 @@
    comphelper::ProfileZone aZone("doc_setTextSelection");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3176,13 +3154,12 @@
    comphelper::ProfileZone aZone("doc_getTextSelection");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }

@@ -3209,13 +3186,12 @@
    comphelper::ProfileZone aZone("doc_paste");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return false;
    }

@@ -3225,8 +3201,7 @@
    pDoc->setClipboard(xClipboard);
    if (!pDoc->isMimeTypeSupported())
    {
        if (gImpl)
            gImpl->maLastExceptionMsg = "Document doesn't support this mime type";
        SetLastExceptionMsg("Document doesn't support this mime type");
        return false;
    }

@@ -3236,7 +3211,7 @@
    }));
    if (!comphelper::dispatchCommand(".uno:Paste", aPropertyValues))
    {
        gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
        SetLastExceptionMsg("Failed to dispatch the .uno: command");
        return false;
    }

@@ -3248,13 +3223,12 @@
    comphelper::ProfileZone aZone("doc_setGraphicSelection");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3266,13 +3240,12 @@
    comphelper::ProfileZone aZone("doc_resetSelection");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3622,7 +3595,7 @@
        ITiledRenderable* pDoc = getTiledRenderable(pThis);
        if (!pDoc)
        {
            gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
            SetLastExceptionMsg("Document doesn't support tiled rendering");
            return nullptr;
        }
        OUString aTrackedChanges = pDoc->getTrackedChanges();
@@ -3640,7 +3613,7 @@
    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return nullptr;
    }
    OUString aAuthors = pDoc->getTrackedChangeAuthors();
@@ -3652,8 +3625,7 @@
    comphelper::ProfileZone aZone("doc_getCommandValues");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    OString aCommand(pCommand);
    static const OString aViewRowColumnHeaders(".uno:ViewRowColumnHeaders");
@@ -3705,7 +3677,7 @@
        ITiledRenderable* pDoc = getTiledRenderable(pThis);
        if (!pDoc)
        {
            gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
            SetLastExceptionMsg("Document doesn't support tiled rendering");
            return nullptr;
        }

@@ -3764,7 +3736,7 @@
        ITiledRenderable* pDoc = getTiledRenderable(pThis);
        if (!pDoc)
        {
            gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
            SetLastExceptionMsg("Document doesn't support tiled rendering");
            return nullptr;
        }

@@ -3817,7 +3789,7 @@
    }
    else
    {
        gImpl->maLastExceptionMsg = "Unknown command, no values returned";
        SetLastExceptionMsg("Unknown command, no values returned");
        return nullptr;
    }
}
@@ -3828,13 +3800,12 @@
    comphelper::ProfileZone aZone("doc_setClientZoom");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3846,13 +3817,12 @@
    comphelper::ProfileZone aZone("doc_setClientVisibleArea");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3865,13 +3835,12 @@
    comphelper::ProfileZone aZone("doc_setOutlineState");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    ITiledRenderable* pDoc = getTiledRenderable(pThis);
    if (!pDoc)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
        SetLastExceptionMsg("Document doesn't support tiled rendering");
        return;
    }

@@ -3884,8 +3853,7 @@
    comphelper::ProfileZone aZone("doc_createView");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    OUString aOptions = getUString(pOptions);
    const OUString aLanguage = extractParameter(aOptions, "Language");
@@ -3909,8 +3877,7 @@
    comphelper::ProfileZone aZone("doc_destroyView");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SfxLokHelper::destroyView(nId);
}
@@ -3920,8 +3887,7 @@
    comphelper::ProfileZone aZone("doc_setView");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SfxLokHelper::setView(nId);
}
@@ -3931,8 +3897,7 @@
    comphelper::ProfileZone aZone("doc_getView");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    return SfxLokHelper::getView();
}
@@ -3942,8 +3907,7 @@
    comphelper::ProfileZone aZone("doc_getViewsCount");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    return SfxLokHelper::getViewsCount();
}
@@ -3953,8 +3917,7 @@
    comphelper::ProfileZone aZone("doc_getViewsIds");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    return SfxLokHelper::getViewIds(pArray, nSize);
}
@@ -3964,8 +3927,7 @@
    comphelper::ProfileZone aZone("doc_setViewLanguage");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    SfxLokHelper::setViewLanguage(nId, OStringToOUString(language, RTL_TEXTENCODING_UTF8));
}
@@ -3979,8 +3941,7 @@
    comphelper::ProfileZone aZone("doc_renderFont");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    OString aSearchedFontName(pFontName);
    OUString aText(OStringToOUString(pChar, RTL_TEXTENCODING_UTF8));
@@ -4094,13 +4055,12 @@
    comphelper::ProfileZone aZone("doc_paintWindowDPI");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
    if (!pWindow)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
        SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
        return;
    }

@@ -4160,13 +4120,12 @@
    comphelper::ProfileZone aZone("doc_postWindow");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
    if (!pWindow)
    {
        gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
        SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
        return;
    }

@@ -4199,7 +4158,7 @@
            Application::PostKeyEvent(VclEventId::WindowKeyInput, pWindow, &aEvent);
        }
        else
            gImpl->maLastExceptionMsg = "Window command 'paste': wrong parameters.";
            SetLastExceptionMsg("Window command 'paste': wrong parameters.");
    }
}

@@ -4381,8 +4340,7 @@
static char* lo_getFilterTypes(LibreOfficeKit* pThis)
{
    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    LibLibreOffice_Impl* pImpl = static_cast<LibLibreOffice_Impl*>(pThis);

@@ -4423,8 +4381,7 @@
    comphelper::ProfileZone aZone("lo_setOptionalFeatures");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    LibLibreOffice_Impl *const pLib = static_cast<LibLibreOffice_Impl*>(pThis);
    pLib->mOptionalFeatures = features;
@@ -4444,8 +4401,7 @@
    comphelper::ProfileZone aZone("lo_setDocumentPassword");

    SolarMutexGuard aGuard;
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();

    assert(pThis);
    assert(pURL);
@@ -4456,8 +4412,7 @@

static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/)
{
    if (gImpl)
        gImpl->maLastExceptionMsg.clear();
    SetLastExceptionMsg();
    const OUString sVersionStrTemplate(
        "{ "
        "\"ProductName\": \"%PRODUCTNAME\", "
@@ -4509,7 +4464,7 @@

    if (!xContext.is())
    {
        gImpl->maLastExceptionMsg = "XComponentContext could not be created";
        SetLastExceptionMsg("XComponentContext could not be created");
        SAL_INFO("lok", "XComponentContext could not be created");
        return false;
    }
@@ -4517,7 +4472,7 @@
    xFactory = xContext->getServiceManager();
    if (!xFactory.is())
    {
        gImpl->maLastExceptionMsg = "XMultiComponentFactory could not be created";
        SetLastExceptionMsg("XMultiComponentFactory could not be created");
        SAL_INFO("lok", "XMultiComponentFactory could not be created");
        return false;
    }