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

Exception.js   A

Complexity

Total Complexity 15
Complexity/F 5

Size

Lines of Code 51
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1024
dl 0
loc 51
ccs 19
cts 19
cp 1
crap 0
rs 10
wmc 15
mnd 1
bc 5
fnc 3
bpm 1.6666
cpm 5
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
B Exception.native 0 8 7
A ➔ Exception 0 3 1
B Exception.toString 0 8 7
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;