@freemework/common
Version:
Common library of the Freemework Project.
105 lines • 3.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FExceptionNativeErrorWrapper = exports.FExceptionNativeObjectWrapper = exports.FException = void 0;
class FException extends Error {
static wrapIfNeeded(likeError) {
if (likeError instanceof FException) {
return likeError;
}
else if (likeError instanceof Error) {
return new FExceptionNativeErrorWrapper(likeError);
}
else {
return new FExceptionNativeObjectWrapper(likeError);
}
}
innerException;
constructor(first, second) {
if (first === undefined) {
super();
this.innerException = null;
}
else {
if (typeof first === "string") {
super(first);
if (second !== undefined && second !== null) {
this.innerException = FException.wrapIfNeeded(second);
}
else {
this.innerException = null;
}
}
else if (first instanceof FException) {
super();
this.innerException = first;
}
else {
throw new Error("Wrong arguments. First agrument should be a string (if present).");
}
}
}
get name() {
return this.constructor.name;
}
toString() {
let messageBuffer = '';
let stackTraceBuffer = '';
messageBuffer += this.constructor.name;
messageBuffer += ': ';
messageBuffer += this.message;
let innerException = this.innerException;
while (innerException !== null) {
messageBuffer += ' ---> ';
messageBuffer += innerException.constructor.name;
messageBuffer += ': ';
messageBuffer += innerException.message;
const innerStack = innerException.stack;
if (innerStack !== undefined) {
stackTraceBuffer += innerStack;
}
else {
stackTraceBuffer += 'No available stack trace';
}
stackTraceBuffer += '\n';
stackTraceBuffer += '--- End of inner exception stack trace ---\n';
innerException = innerException.innerException;
}
const stackTrace = this.stack;
if (stackTrace !== undefined) {
stackTraceBuffer += stackTrace;
}
else {
stackTraceBuffer += 'No available stack trace';
}
messageBuffer += '\n';
messageBuffer += stackTraceBuffer;
return messageBuffer.toString();
}
}
exports.FException = FException;
class FExceptionNativeObjectWrapper extends FException {
nativeObject;
constructor(nativeObject) {
super(`${nativeObject}`);
this.nativeObject = nativeObject;
}
}
exports.FExceptionNativeObjectWrapper = FExceptionNativeObjectWrapper;
class FExceptionNativeErrorWrapper extends FException {
nativeError;
constructor(nativeError) {
super(nativeError.message);
this.nativeError = nativeError;
}
get name() {
return this.nativeError.name;
}
toString() {
let messageBuffer = this.nativeError.toString();
messageBuffer += "\n";
messageBuffer += this.nativeError.stack;
return messageBuffer;
}
}
exports.FExceptionNativeErrorWrapper = FExceptionNativeErrorWrapper;
//# sourceMappingURL=f_exception.js.map