ExceptionID.js - showcase
Code:
var EidRuntimeException = Eid.exceptions.EidRuntimeException;
try {
// Example entity objects
var users = [];
for (var i = 0; i < 5; i++) {
var user = { id: 67112 - i };
user.toString = function() { return '[User id=' + this.id + ']'; };
users.push(user);
}
// logging support
for (var i = 0; i < users.length; i++) {
var user = users[i];
var eid = new Eid('20160111:223928', 'WJS-17');
log.debug(eid.makeLogMessage('An entity: %s', user));
log.debug(eid.makeLogMessage('%s has even ID: %s', user, user.id % 2 === 0));
}
// preconditions!
var EidPreconditions = Eid.preconditions;
EidPreconditions.checkArgument(true, '20160111:223749');
EidPreconditions.checkState(false, '20160111:224215', 'A extra message');
} catch(e) {
// Top level of your application
log.error(e.stack);
if (e instanceof EidRuntimeException) {
// or better save your exceptions!
logGateway.put(e, inspectable({eid: e.eid}));
}
}
Console: