术语 - 事件可以被“抛出”吗?

发布于 2024-07-16 02:37:26 字数 134 浏览 3 评论 0原文

这周两次,我读到人们写到一个事件(.net)被“抛出”。 我一直认为与事件一起使用的动词是“fire”或“raise”。 我认为“抛出”用于异常,而不是事件(“引发”可以用于任何一个)。

还有其他人觉得“抛出”事件令人困惑吗?

Twice this week, I've read people write that an event (.net) was "thrown". I've always thought that the verb to use with events is either "fire" or "raise". I thought that "thrown" was used for exceptions, but not events ("raise" can be used for either).

Does anyone else find it confusing for events to be "thrown"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

过潦 2024-07-23 02:37:26

我同意,事件被引发/触发/触发。 如果抛出任何东西,那就是异常。

I agree, events are raised/fired/triggered. If anything is thrown it's exceptions.

往事风中埋 2024-07-23 02:37:26

MSDN 库中的标准约定似乎是指 引发事件抛出异常

The standard convention in the MSDN library seems to refer to Raising an Event and Throwing an Exception.

私野 2024-07-23 02:37:26

另一个术语是“调用”。 由于事件是代理,因此它们被调用来调用它们,但是通用术语是“解雇”或“引发”。

此外,在这种情况下使用“ throw”一词会令人困惑,因为它会与“ throw”关键字相混淆。 您不能使用 throw 关键字引发事件。

One other term is "Invoked". Since events are delgates, they are Invoked to call them, but yes the general term is either "fired" or "raised".

Also, use of the word "throw" in this context is confusing, because it will be confused with the "throw" keyword. You can't throw an event with the throw keyword.

孤城病女 2024-07-23 02:37:26

Raise 是 MSDN 文档中最常见的动词。

我同意 - 如果我听说有什么东西被抛出,我认为这是一个例外。 C# 语言使这一点变得非常明确 - throw 是与异常一起使用的保留字。

Raise is the verb that seems to be most common in the MSDN docs.

I agree - if I hear that something was thrown, I assume it's an exception. The C# language makes that one very explicit - throw is a reserved word used with exceptions.

月依秋水 2024-07-23 02:37:26

尽管可以抛出不是异常的东西,但很明显throw仅适用于异常。 Raise确实是用来表示事件已经发生的术语。

Although it's possible to throw things that aren't exceptions, it's quite clear that throw is only meant to be used with exceptions. Raise is indeed the term you'd use for signifying that an event has happened.

疯狂的代价 2024-07-23 02:37:26

不,它们不能被扔掉,但就像矮人和霍比特人一样,它们可以被扔掉。

No, they can't be thrown, but much like dwarves and hobbits, they can be tossed.

岁吢 2024-07-23 02:37:26

我认为事件可以被抛出,但如果你真的这样做,那就是不称职的编码。

让我解释。 在 C++ 中你可以抛出任何类型。 您可以抛出布尔值。 您可以抛出枚举error_type。 您可以抛出std::Exception。 当然,您可以抛出struct XEvent

但如果你确实这样做的话,你很可能正在做一些严重错误或非常令人困惑(因此错误)的事情。

我完全赞成不要超载单词的含义,以避免歧义(在不需要存在的情况下)。

我认为“抛出”通常被理解为暗示调用堆栈展开(当您有一个明确定义的堆栈时,但我认为它可以扩展到无界入度的单链表;即父指针树)。 让我们坚持这一点。

“raise”一词也用于信号。 如果也可以避免在事件中使用它,那就太好了。

我更喜欢在事件发生时“触发”(“onMouseOver 事件刚刚触发”),并且当事件侦听器通知使用者时可能“发出信号”(“XMouseMotionNotify 事件已向客户端发出信号”)。

I think events can be thrown, but it's incompetent coding if you actually do.

Let me explain. In C++ you can throw any type. You can throw booleans. You can throw enum error_type. You can throw std::exception. And of course you can throw struct XEvent.

But you most likely are doing something either horribly wrong or horribly confusing (and thus wrong) if you actually do.

I'm all for not overloading the meanings of words, to avoid ambiguity (where it doesn't need to exist).

I think "throw" is commonly understood to imply call stack unwinding (for when you have a well-defined stack, but I think it can be extended to a singly linked list of unbounded in-degree; that is, a tree of parent pointers). Let's stick to that.

The word "raise" is used for signals as well. It'd be nice if it's possible to avoid using this for events too.

I prefer "fired" for when the event happens ("the onMouseOver event just fired"), and maybe "was signalled" when the event listener notifies the consumer ("the XMouseMotionNotify event was signalled to the client").

隱形的亼 2024-07-23 02:37:26

您通常会听到人们提到被解雇或提出的事件。 但在我看来,抛出完全没问题。 关键是他们是否说该事件被抛出。

不要尝试将头发分成很多。 我们的职业已经足够复杂,拥有数千种技术,更不用说考虑我们沟通方式的细微差别了。

You typically hear people refer to events being fired or raised. But thrown is perfectly fine in my opinion. The key is if they say the event was thrown.

Don't try and split to many hairs. Our profession is complicated enough with the thousands of technologies let alone thinking about the tiny nuances of how we communicate.

热鲨 2024-07-23 02:37:26

我想说你发布一个活动。

I'd say you publish an Event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文