如果我将ADA中的范围定义为1 ... 1000,如果我增加超过1000,ADA规范是否有定义的行为?
例如:
type Index is range 1..1000;
idx : Index := 1;
procedure Increment is
begin
idx := idx + 1;
end
一旦我用idx = 1000调用Increment,我应该发生什么?
答案 0 :(得分:5)
您的程序将失败并显示CONSTRAINT_ERROR
。但是,这并不是因为您最终尝试将idx
设置为1001.而是将其初始值0设置为不在预定义范围内。值得庆幸的是,编译器已经在编译时警告过你这个事实。
如果您已将idx
设置为允许值,然后以编译器无法静态检测的方式将其增加到超出其上限,则将再次CONSTRAINT_ERROR
引发(但不会有任何值// break it into understandable chunks, too, so, here's a function
// to build a Locations object from the http data
function locationFromResult(result) {
var Location = Parse.Object.extend("Locations");
var restaurant = new Location();
var placeId = result.place_id;
var name = result.name;
var vicinity = result.vicinity;
var point = new Parse.GeoPoint({
latitude: result.geometry.location.lat,
longitude: result.geometry.location.lng
});
restaurant.set("placeId", placeId);
restaurant.set("name", name);
restaurant.set("vicinity", vicinity);
restaurant.set("location", point);
return restaurant;
}
Parse.Cloud.job("requestLocations", function (request, response) {
var url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=29.7030428,-98.1364808&radius=900&types=restaurant&key=AIzaSyCTg0x68Q6lrCAo6-A37zkxge81jDEKpvo';
Parse.Cloud.httpRequest({url: url}).then(function (httpResponse) {
var parsedData = JSON.parse(httpResponse.text);
var locations = parsedData.results.map(function(result) {
return locationFromResult(result);
});
// this is important, saveAll of the new objects before returning
// this can also be accomplished by saving the objects individually and using Parse.Promise.when()
return Parse.Object.saveAll(locations);
}).then(function(result) {
response.success(JSON.stringify(result));
}, function(error) {
response.error(JSON.stringify(error));
});
});
提示编译时)。
从技术上讲,此错误是exception,您可以像处理该语言中的任何其他异常一样处理该错误。
注意:我故意链接到上面古老的Ada '83规范,表明这种行为从一开始就是语言的一部分。