Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support error instance #1

Merged
merged 2 commits into from
Jan 19, 2016
Merged

Support error instance #1

merged 2 commits into from
Jan 19, 2016

Conversation

blond
Copy link
Contributor

@blond blond commented Jan 18, 2016

Sometimes it is necessary to report error with the help of special custom error.

Example:

var thr = require('throw');

// Create a new object, that prototypally inherits from the Error constructor
function MyError(message) {
  this.name = 'MyError';
  this.message = message || 'Default Message';
  this.stack = (new Error(message)).stack;
}
MyError.prototype = Object.create(Error.prototype);
MyError.prototype.constructor = MyError;

var arg = arg || thr(new MyError());

@anton-rudeshko
Copy link
Owner

I think it's better to parametrize with error constructor like this:

var arg = arg || thr(MyError, 'message %s - %s', arg1, arg2);

@blond
Copy link
Contributor Author

blond commented Jan 19, 2016

It is impossible to support message format for custom error class, because constructor can contain multiple arguments.

@blond
Copy link
Contributor Author

blond commented Jan 19, 2016

Added parameterization of error class.

anton-rudeshko added a commit that referenced this pull request Jan 19, 2016
@anton-rudeshko anton-rudeshko merged commit 6aaed53 into anton-rudeshko:master Jan 19, 2016
@anton-rudeshko
Copy link
Owner

GJ 🎉 Thanks

@blond
Copy link
Contributor Author

blond commented Jan 19, 2016

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants