Completed
Push — master ( 528146...2a864a )
by Esaú
01:42
created

Exception.js ➔ Exception   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
// Exception.js
2
"use strict";
3
4
// :: DEPENDENCIES
5
6
// load native dependencies
7 1
const path = require("path");
8
9
// load local dependencies
10 1
const Throwable = require(path.join(__dirname, "Throwable.js"));
11
12
// :: BASIC SETUP
13
14
// empty 'class'
15 1
const Exception = function (name, message, code) {
16 2060
    Throwable.call(this, name, message, code);
17
};
18
19
// :: INHERITANCE
20
21
// set the prototype chain parent to the Throwable 'class'
22 1
Exception.prototype = Object.create(Throwable.prototype);
23
24
// set the prototype chain constructor
25 1
Exception.prototype.constructor = Exception;
26
27
// :: PROTOTYPE
28
29
// set the toString method
30 1
Exception.prototype.toString = function () {
31 24
    let str = (this.name !== null && this.name !== undefined ? this.name : "Exception");
32 24
    if (this.code !== null && this.code !== undefined) {
33 4
        str += " (0x" + this.code.toString(16) + ")";
34
    }
35 24
    str += ": " + (this.message !== null && this.message !== undefined ? this.message : "thrown") + ".";
36 24
    return str;
37
};
38
39
// returns a native 'Error'
40 1
Exception.prototype.native = function () {
41 24
    let str = (this.name !== null && this.name !== undefined ? this.name : "Exception");
42 24
    if (this.code !== null && this.code !== undefined) {
43 4
        str += " (0x" + this.code.toString(16) + ")";
44
    }
45 24
    str += ": " + (this.message !== null && this.message !== undefined ? this.message : "thrown");
46 24
    return new Error(str);
47
};
48
49
// :: EXPORT
50
51
// export the Exception 'class'
52
module.exports = Exception;