Тёмный

Creating your own custom Syntax Errors in Javascript! (SyntaxError) 

dcode
Подписаться 135 тыс.
Просмотров 1,6 тыс.
50% 1

For a bit of fun, today we are looking at making your own custom SyntaxError objects in Javascript - I bet a lot of you didn't know you could do something like this! ;)
Here is what inspired me to make this video:
developer.mozi...
It's probably useless most of the time, but still interesting to know!
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

Опубликовано:

 

20 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 4   
@dcode-software
@dcode-software 6 лет назад
Can you think of any scenarios where this would be useful?
@harag9
@harag9 6 лет назад
This is very useful in .net, so I assume it will be useful in javascript - if you have a large JS project, it's useful for bubbling up the errors through the function. So you have your "main" function at the top with the try catch, and then sub functions in the try, if they error you then throw them errors, which then bubble up to the main function and that then can display / log the error to the user / developer - helps to cleanly exit out of the sub functions. Hope this makes sense.
@dcode-software
@dcode-software 6 лет назад
I think so, but would they be syntax errors?
@quanzt
@quanzt 2 года назад
it is useful in constructor assign to a data field in which is required. constructor ({ dataField = isRequired('dataField')}) { this.dataField = dataField } ... const isRequired = name => { throw new SyntaxError(`${name} is required.` }
Далее
There's Way More to JSON.Stringify Than You Think
9:26
How to Install and Use an Adjustable TV Arm
00:18
Просмотров 821 тыс.
JavaScript Pro Tips - Code This, NOT That
12:37
Просмотров 2,5 млн
3 TYPES OF ERRORS in JavaScript, using code examples
4:39
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
Просмотров 895 тыс.