Home > Net >  WCF service side method if there is any need to add the try catch?
WCF service side method if there is any need to add the try catch?

Time:10-24

WCF service side method if there is any need to add the try catch? I read a book, WCF is the exception handling mechanism, the error is sent to the client, the client can try to catch mistakes, so do you want to add to the WCF service method try catch, my own test, do not add try catch is allowed, but not be at ease, one thousand some exceptions cannot capture, cause server crash?

CodePudding user response:

,,,,,, yes
To handle exceptions, of course, global handle exceptions, but you can not try catch every place

CodePudding user response:

You ask is not technical problem, this is a system need not

1000 client often error, for example, your leadership is in the middle of the complaints and angry in the morning, let you troubleshoot problems, said "must solve, overtime has to solve, not solve everyone mustn't come home, to I live in the company"

Here's the thing, please tell me where is the mistake? What happen? What condition happened, we how to reappear this error?

You ignore him, there is no record, you also don't know how this error emersion, programmers know that problem, we don't bother error, we bother you tell me the mistake, I test hundreds times repetition can't he

CodePudding user response:

Don't write the try.. Catch the code is more confident in yourself,

CodePudding user response:

Just like before you send the code, this is the reason for obviously,

Wrong, be complaints, and must be solved, not solve buckles money

ok? What's wrong? I don't know

Anyway, I don't know, I need to change anyway? How to change, how to optimize? Asynchronous, thread, brush, also not line? Add ngnix shunt

So, you know I often against the blog garden, because these are blog tell you in the garden, as for, Don't know, because you don't know what is wrong, anyway, blog garden said ok, so it is so, as it happens, return true to ok

Ps: there is a problem in your code actually, anomaly is the default (T), then the problem is coming, are you really the default or abnormal?? Such as someone once asked me they often can't get the data and the upper according to the garden on a blog, the man finally found is actually the bottom ate anomaly (originally is a problem of the bottom, but you eat, the above screening various optimizing for a few months, there is no effect)

CodePudding user response:

The complexity of the function is necessary, see,

To make it easier to find the problem, and personalized handle exceptions,

A certain level in the call, may need to encapsulate the catch the exception, and then throw to the outside,

Such as: direct database access layer which table can be according to the current access methods, such as the record about the specific information, thrown to the business layer, business layer to record this is which business, which implementation module, etc., and then threw the WCF implementation layer, implementation layer organization information structure, oneself's record run log, and returned to the client,

The client according to the information displayed on the interface once more "professional" error message,

Client in the client take a photo to you, you know where is wrong, according to the key information

Of course this is admirable

CodePudding user response:

refer to 6th floor fly4free response: ,
necessary functional complexity,

To make it easier to find the problem, and personalized handle exceptions,

A certain level in the call, may need to encapsulate the catch the exception, and then throw to the outside,

Such as: direct database access layer which table can be according to the current access methods, such as the record about the specific information, thrown to the business layer, business layer to record this is which business, which implementation module, etc., and then threw the WCF implementation layer, implementation layer organization information structure, oneself's record run log, and returned to the client,

The client according to the information displayed on the interface once more "professional" error message,

Client in the client take a photo to you, you know where is wrong, according to the key information

Of course this is idealized situation


Is I spent a day with these two problems, not add don't add try catch the problem, I want to unified handling exceptions in the interceptor, then no longer write methods try catch, think about it, you write 100 method, the results have 10 forget to write down the try catch, this is often the case, as I write this to forget to write the try catch, if there is a mechanism to solve the abnormal WCF, I don't have to write a try catch, don't have to worry about forget to write down, this is of great significance. Is of great significance.

CodePudding user response:

Well, the key place a also enough,

Everywhere, the inner call might also shielding problem, more difficult to find the problem,
  •  Tags:  
  • C#
  • Related