exception-handling

using catch(…) (ellipsis) for post-mortem analysis

江枫思渺然 提交于 2019-12-29 05:13:06
问题 Someone in a different question suggested using catch(...) to capture all otherwise unhandled - unexpected/unforseen exceptions by surrounding the whole main() with the try{}catch(...){} block. It sounds like an interesting idea that could save a lot of time debugging the program and leave at least a hint of what happened. The essence of the question is what information can be recovered that way (other than whatever debug globals I leave behind), and how to recover it (how to access and

Where/what level should logging code go?

假如想象 提交于 2019-12-29 03:29:08
问题 I'm wondering where logging code should go. For example, should my repository log it's own errors? Or should I log all errors from the UI/controller? Are there any general deisgn principles about this, or does anyone have link to a good article or somesuch. 回答1: Logging and tracing is (IMO) a fine art, knowing what to log and where takes experience. I've found that the best (worst?) way of learning the art of logging is by experiencing the pain of attempting to diagnose issues with shoddy

Where/what level should logging code go?

最后都变了- 提交于 2019-12-29 03:29:07
问题 I'm wondering where logging code should go. For example, should my repository log it's own errors? Or should I log all errors from the UI/controller? Are there any general deisgn principles about this, or does anyone have link to a good article or somesuch. 回答1: Logging and tracing is (IMO) a fine art, knowing what to log and where takes experience. I've found that the best (worst?) way of learning the art of logging is by experiencing the pain of attempting to diagnose issues with shoddy

What is wrong with “checking for self-assignment” and what does it mean?

假装没事ソ 提交于 2019-12-29 03:14:30
问题 In Herb Sutter's book Exceptional C++ (1999) , he has words in item 10's solution: "Exception-unsafe" and "poor design" go hand in hand. If a piece of code isn't exception-safe, that's generally okay and can simply be fixed. But if a piece of code cannot be made exception-safe because of its underlying design, that almost always is a signal of its poor design. Example 1: A function with two different responsibilities is difficult to make exception-safe. Example 2: A copy assignment operator

What is wrong with “checking for self-assignment” and what does it mean?

↘锁芯ラ 提交于 2019-12-29 03:14:08
问题 In Herb Sutter's book Exceptional C++ (1999) , he has words in item 10's solution: "Exception-unsafe" and "poor design" go hand in hand. If a piece of code isn't exception-safe, that's generally okay and can simply be fixed. But if a piece of code cannot be made exception-safe because of its underlying design, that almost always is a signal of its poor design. Example 1: A function with two different responsibilities is difficult to make exception-safe. Example 2: A copy assignment operator

Return custom error objects in Web API

五迷三道 提交于 2019-12-29 02:43:27
问题 I have a web API I'm working on using the MVC 4 Web API framework. If there is an exception, I'm currently throwing a new HttpResponseException. ie: if (!Int32.TryParse(id, out userId)) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid id")); This returns an object to the client that is simply {"message":"Invalid id"} I would like to gain further control over this response to exceptions by returning a more detailed object. Something like { "status

Getting “Recursive collection data contract” when referencing a WCF service with a slightly complex method

心不动则不痛 提交于 2019-12-29 00:25:08
问题 If I use only simple methods in my WCF service, everything works fine. However, if I include the following method, a problem occurs: [OperationContract] public List<KeyValuePair<string, string>> GetAllAccounts() { return AccountBusiness.GetAllAccounts(); } I get this error when referencing the service from another project: Warning 5 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description

Can I remove empty catch with throw?

寵の児 提交于 2019-12-28 16:30:45
问题 I'm hoping this is straightforward. I work on a large code-base, the overall quality is good, but occasionally you get some of these: try { // Calls a .NET remoting method. } catch { throw; } Note there is no finally logic and the catch does not specify any exceptions or do anything other than what I've provided above. However, I know that catching and re-throwing can alter the call-stack in the exception details. What I'm not sure about is if this behaviour is here specifically because of a

c++ abort override

ⅰ亾dé卋堺 提交于 2019-12-28 16:13:10
问题 Some C++ libraries call abort() function in the case of error (for example, SDL). No helpful debug information is provided in this case. It is not possible to catch abort call and to write some diagnostics log output. I would like to override this behaviour globally without rewriting/rebuilding these libraries. I would like to throw exception and handle it. Is it possible? 回答1: Note that abort raises the SIGABRT signal, as if it called raise(SIGABRT) . You can install a signal handler that

c++ abort override

拟墨画扇 提交于 2019-12-28 16:13:04
问题 Some C++ libraries call abort() function in the case of error (for example, SDL). No helpful debug information is provided in this case. It is not possible to catch abort call and to write some diagnostics log output. I would like to override this behaviour globally without rewriting/rebuilding these libraries. I would like to throw exception and handle it. Is it possible? 回答1: Note that abort raises the SIGABRT signal, as if it called raise(SIGABRT) . You can install a signal handler that