Is there a way to extract when an exception was thrown from the exception itself, or will I need to manually add this information to the exception?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There is no built-in Timestamp
property for the Exception
object. You can create a new class that inherits from Exception
and add your own property.
If you're using your exception as a parameter of a log framework, you might want to handle the timestamp directly in the log framework (most probably using DateTime.Now
/ UtcNow
).
回答2:
When an exception occurs, and IF you have handled it, then the control will immediately go to the catch block thats exactly the time when an exception occured
So the first line in catch block could get you exactly when using date object
(DateTime.Now.Time
etc)