예: 고스트 엔티티 생성 및 삭제
다음 예를 실행하면 고스트 사물이 만들어집니다.
var params = {
name: "GhostThing" /* STRING */,
description: "Ghost" /* STRING */,
thingTemplateName: "GenericThing" /* THINGTEMPLATENAME */
};
// Successfully creates the GhostThing entity.
Resources["EntityServices"].CreateThing(params);
// Code that will cause an exception to be thrown by the service.
var makeError;
// Exception is thrown as the notThere property does not exist
on the makeError variable at this point.
makeError.notThere = 1;
"try-catch" 메커니즘을 사용하여 고스트 엔티티를 삭제합니다.
try {
var params = {
name: "GhostThing" /* STRING */,
description: "Ghost" /* STRING */,
thingTemplateName: "GenericThing" /* THINGTEMPLATENAME */
};
Resources["EntityServices"].CreateThing(params);
// Any code that could potentially cause an exception should
// be included in the try-catch block.
// The following code will cause an exception to be thrown
// as makeError.notThere has not been defined.
var makeError;
makeError.notThere = 1;
} catch (err) {
// If an exception is caught, we need to delete the entity
// that was created to prevent it from becoming a Ghost Entity
var params = {
name: "GhostThing" /* THINGNAME */
};
Resources["EntityServices"].DeleteThing(params);
}