![]() ![]() ![]() For instance, HttpTimeoutError may inherit from HttpError, and so on. So it’s better to inherit from it.Īs the application grows, our own errors naturally form a hierarchy. But if we inherit, then it becomes possible to use obj instanceof Error to identify error objects. JavaScript allows to use throw with any argument, so technically our custom error classes don’t need to inherit from Error. HttpError objects may have a statusCode property with a value like 404 or 403 or 500. But they also may have other properties of their own, e.g. Our errors should support basic error properties like message, name and, preferably, stack. For errors in network operations we may need HttpError, for database operations DbError, for searching operations NotFoundError and so on. When we develop something, we often need our own error classes to reflect specific things that may go wrong in our tasks.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |