git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59452
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// Tries to dynamically construct an object of the right class.
wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
{
// Tries to dynamically construct an object of the right class.
wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
{
- wxDocument * const doc = DoCreateDocument();
+ wxScopedPtr<wxDocument> doc(DoCreateDocument());
- // VZ: this code doesn't delete doc if InitDocument() (i.e. doc->OnCreate())
- // fails, is this intentional?
-
- return doc && InitDocument(doc, path, flags) ? doc : NULL;
+ return doc && InitDocument(doc.get(), path, flags) ? doc.release() : NULL;
docNew->SetDocumentName(temp->GetDocumentName());
docNew->SetDocumentTemplate(temp);
docNew->SetDocumentName(temp->GetDocumentName());
docNew->SetDocumentTemplate(temp);
- // call the appropriate function depending on whether we're creating a new
- // file or opening an existing one
- if ( !(flags & wxDOC_NEW ? docNew->OnNewDocument()
- : docNew->OnOpenDocument(path)) )
- // Document is implicitly deleted by DeleteAllViews
- docNew->DeleteAllViews();
- return NULL;
+ // call the appropriate function depending on whether we're creating a
+ // new file or opening an existing one
+ if ( !(flags & wxDOC_NEW ? docNew->OnNewDocument()
+ : docNew->OnOpenDocument(path)) )
+ {
+ docNew->DeleteAllViews();
+ return NULL;
+ }
+ wxCATCH_ALL( docNew->DeleteAllViews(); throw; )
// add the successfully opened file to MRU, but only if we're going to be
// able to reopen it successfully later which requires the template for
// add the successfully opened file to MRU, but only if we're going to be
// able to reopen it successfully later which requires the template for