Commit ebd31772 authored by Leander Schulten's avatar Leander Schulten
Browse files

Catch exceptions when creating a ControlItem

parent 39f28967
Pipeline #169613 passed with stage
in 1 minute and 44 seconds
......@@ -4,6 +4,7 @@
#include <QJsonArray>
#include <exception>
#include <QQmlContext>
#include "errornotifier.h"
namespace GUI{
......@@ -54,14 +55,19 @@ void ControlPanel::loadFromJsonObject(const QJsonObject &o){
const auto array = o["ControlItems"].toArray();
for(const auto o_ : array){
const auto o = o_.toObject();
if(o["type"].toInt()==ControlItemData::PROGRAMM){
createControlItem(programm,new ProgrammControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::SWITCH_GROUP){
createControlItem(switchGroup,new SwitchGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::DIMMER_GROUP){
createControlItem(dimmerGroup,new DimmerGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::PROGRAM_BLOCK){
createControlItem(programBlock,new ProgramBlockControlItemData(o));
try {
if(o["type"].toInt()==ControlItemData::PROGRAMM){
createControlItem(programm,new ProgrammControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::SWITCH_GROUP){
createControlItem(switchGroup,new SwitchGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::DIMMER_GROUP){
createControlItem(dimmerGroup,new DimmerGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::PROGRAM_BLOCK){
createControlItem(programBlock,new ProgramBlockControlItemData(o));
}
} catch (const std::runtime_error &e) {
const auto typeNames = {"Program","SwitchGroup","DimmerGroup","ProgramBlock"};
ErrorNotifier::showError(QString("Error while creating a ControlItem of Type ") + typeNames.begin()[o["type"].toInt()] + "\nCause: " + e.what());
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment