Make wxDocTemplate::CreateDocument() exceptions-safe.
Don't create the document object if InitDocument() throws. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71371 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -859,17 +859,19 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
|
|||||||
bool
|
bool
|
||||||
wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
|
wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
|
||||||
{
|
{
|
||||||
|
wxScopeGuard g = wxMakeObjGuard(*doc, &wxDocument::DeleteAllViews);
|
||||||
|
|
||||||
doc->SetFilename(path);
|
doc->SetFilename(path);
|
||||||
doc->SetDocumentTemplate(this);
|
doc->SetDocumentTemplate(this);
|
||||||
GetDocumentManager()->AddDocument(doc);
|
GetDocumentManager()->AddDocument(doc);
|
||||||
doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
|
doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
|
||||||
|
|
||||||
if (doc->OnCreate(path, flags))
|
if ( !doc->OnCreate(path, flags) )
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if (GetDocumentManager()->GetDocuments().Member(doc))
|
g.Dismiss(); // no need to call DeleteAllViews() anymore
|
||||||
doc->DeleteAllViews();
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
|
wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
|
||||||
|
Reference in New Issue
Block a user