Using the Exception class only as a transport mechanism?

I'm not sure this is a great idea and you want to request a community. How about using Exception instances to only transfer data and not throw it away? For the situation, I need to transfer the exception information to a container of some type for the purpose of registration or reporting. The Exception data structure is just like the information I need to pass in my program, so I'm considering combining it.

Exception instances are a convenient way to pack information about an exception, which need not be thrown. For example, exceptional data should be returned as status information (such as XML) as a response to a web service call in the application. To do this, I do not need to call the exception handling system and its resources.

Which Exception class is understood at all application levels (in the System namespace), so it can be used as a container without a reference in another assembly or without creating a custom class. Exceptions can also be considered as ordinary objects, for example, return values โ€‹โ€‹of methods, and they do not need to be thrown.

Plus the app can choose to start throwing them if it ever wishes, I suppose.

+3
source share
3

, , - , .

Exception, , . .

Exception , "" .

+2

, . dll, , . , , Exception.

0

, , , ?
.

, . - .

And you should not use a common class Exception, use derived classes, or create your own. I know it takes some time, but it will pay for itself when tracking code issues.

-1
source

Source: https://habr.com/ru/post/1795763/


All Articles