D
D
Denis11112018-07-30 11:33:25
JavaScript
Denis1111, 2018-07-30 11:33:25

Why is "e" undefinable?

Why is "e" undefined?

var util = require('util');

var phrases = {
    "Hello": "Привет",
    "world": "мир"
}

function PhraseError(message) {
    this.message = message;
}

util.inherits(PhraseError, Error);
PhraseError.prototype.name = "PhraseError";

function HttpError(status, message) {
    this.status = status;
    this.message = message;
}

util.inherits(HttpError, Error);
HttpError.prototype.name = "HttpError";

function getPhrase(name) {
    if (!phrases[name]) {
        throw PhraseError('Phrase is not defind' + name)
    }
    return phrases[name];
}

function makePage(url) {
    if (url !== "index.html") {
        throw HttpError(404, "Page is not defind");
    }
    return util.format("%s, %s!", getPhrase("asdasd"), getPhrase("world"));
}

try {
    var page = makePage("index.html");
    console.log(page);
} catch (e) {
    console.log(e); //undefind
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-07-30
@Denis1111

throw PhraseError

Missed somewhere new. The same applies to calling HttpError.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question