diff --git a/headers/os/interface/Shelf.h b/headers/os/interface/Shelf.h index cd068f8c3a..26263561ed 100644 --- a/headers/os/interface/Shelf.h +++ b/headers/os/interface/Shelf.h @@ -99,6 +99,8 @@ class BShelf : public BHandler { status_t _AddReplicant(BMessage* data, BPoint* location, uint32 uniqueID); status_t _GetProperty(BMessage* message, BMessage* reply); + + static BArchivable* _InstantiateObject(BMessage *archive, image_id *image); private: BView* fContainerView; diff --git a/src/kits/interface/Shelf.cpp b/src/kits/interface/Shelf.cpp index 19e30f83a6..dc82a53c2e 100644 --- a/src/kits/interface/Shelf.cpp +++ b/src/kits/interface/Shelf.cpp @@ -1140,7 +1140,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) // Instantiate the object, if this fails we have a zombie image_id image; - BArchivable *archivable = instantiate_object(data, &image); + BArchivable *archivable = _InstantiateObject(data, &image); if (archivable) { BView *view = dynamic_cast(archivable); BPoint point; @@ -1157,7 +1157,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) if (data->FindMessage("__widget", &widget) == B_OK) { image_id draggerImage = B_ERROR; replicant = view; - dragger = dynamic_cast(instantiate_object(&widget, &draggerImage)); + dragger = dynamic_cast(_InstantiateObject(&widget, &draggerImage)); if (dragger != NULL) { // Replicant is either a sibling or unknown dragger->_SetViewToDrag(replicant); @@ -1325,3 +1325,19 @@ BShelf::_GetProperty(BMessage *msg, BMessage *reply) return err; } + + +/* static */ +BArchivable * +BShelf::_InstantiateObject(BMessage *archive, image_id *image) +{ + // Stay on the safe side. The constructor called by instantiate_object + // could throw an exception, which we catch here. Otherwise our calling app + // could die without notice. + try { + return instantiate_object(archive, image); + } catch (...) { + return NULL; + } +} +