exception-handling

intermixing c++ exception handling and SEH (windows)

点点圈 提交于 2020-01-01 03:36:11
问题 I have a function in which I call getaddrinfo() to get an sockaddr* which targets memory is allocated by the system. As many may know, you need to call freeaddrinfo() to free the memory allocated by getaddrinfo(). Now, in my function, there are a few places, where I may throw an exception, because some function failed. My first solution was to incorporate the freeaddrinfo() into every if-block. But that did look ugly for me, because I would have had to call it anyways before my function

Error parsing AppSettings value with a query string

霸气de小男生 提交于 2020-01-01 01:35:13
问题 In my AppSettings in web.config, I have something like this: <appSettings> <add key="ExternalSystemUrl" value="http://domain.com/page.aspx?id={0}&action=eat&object=bacon" /> </appSettings> However, it seems that when an ampersand ( & ) is included in an AppSettings value, ASP.NET throws the following error: An error occurred while parsing EntityName Why does this happen, and how can I include URLs like this in App.config? 回答1: Replace & with & (escape it): <add key="ExternalSystemUrl" value=

Laravel check for constraint violation

末鹿安然 提交于 2019-12-31 20:01:39
问题 I was curious if there is a way we can check if there is a constraint violation error when delete or insert a record into the database. The exception thrown is called 'QueryException' but this can be a wide range of errors. Would be nice if we can check in the exception what the specific error is. 回答1: You are looking for the 23000 Error code (Integrity Constraint Violation) . If you take a look at QueryException class, it extends from PDOException, so you can access to $errorInfo variable.

Should I throw on null parameters in private/internal methods?

女生的网名这么多〃 提交于 2019-12-31 19:54:01
问题 I'm writing a library that has several public classes and methods, as well as several private or internal classes and methods that the library itself uses. In the public methods I have a null check and a throw like this: public int DoSomething(int number) { if (number == null) { throw new ArgumentNullException(nameof(number)); } } But then this got me thinking, to what level should I be adding parameter null checks to methods? Do I also start adding them to private methods? Should I only do

Should I throw on null parameters in private/internal methods?

笑着哭i 提交于 2019-12-31 19:52:26
问题 I'm writing a library that has several public classes and methods, as well as several private or internal classes and methods that the library itself uses. In the public methods I have a null check and a throw like this: public int DoSomething(int number) { if (number == null) { throw new ArgumentNullException(nameof(number)); } } But then this got me thinking, to what level should I be adding parameter null checks to methods? Do I also start adding them to private methods? Should I only do

Should I throw on null parameters in private/internal methods?

我的梦境 提交于 2019-12-31 19:52:05
问题 I'm writing a library that has several public classes and methods, as well as several private or internal classes and methods that the library itself uses. In the public methods I have a null check and a throw like this: public int DoSomething(int number) { if (number == null) { throw new ArgumentNullException(nameof(number)); } } But then this got me thinking, to what level should I be adding parameter null checks to methods? Do I also start adding them to private methods? Should I only do

Automated Exception Handling

瘦欲@ 提交于 2019-12-31 10:46:26
问题 I was wondering if something exists (in Java world) able to take an snapshot of the JVM current state with the following features: Do it while an exception is being thrown. Capture local variables, method's arguments, etc. Put it in a handy file which can be used to extract or reproduce in a IDE the situation in your source code. The two first features are required (third would be awesome). And it must be suitable for production use (so, there is no way about debuggers). Before asking this I

WCF Service returning “requested service '…' could not be activated” the first time it's accessed from an MVC site

有些话、适合烂在心里 提交于 2019-12-31 10:28:20
问题 We have a WCF service (with no security) that is being accessed by an MVC3 website. On the developer machines we have no problems with it but when our TeamCity setup builds the central version and deploys it under IIS7 the first time we load the MVC3 site and it accesses the WCF service - the service call returns the message: System.ServiceModel.ServiceActivationException: The requested service, 'http://localhost:83/ABCStaticData/StaticDataService.svc' could not be activated. See the server's

Detecting a Dispose() from an exception inside using block

我只是一个虾纸丫 提交于 2019-12-31 09:21:08
问题 I have the following code in my application: using (var database = new Database()) { var poll = // Some database query code. foreach (Question question in poll.Questions) { foreach (Answer answer in question.Answers) { database.Remove(answer); } // This is a sample line that simulate an error. throw new Exception("deu pau"); database.Remove(question); } database.Remove(poll); } This code triggers the Database class Dispose() method as usual, and this method automatically commits the

Is try/catch around whole C# program possible?

我只是一个虾纸丫 提交于 2019-12-31 08:57:13
问题 A C# program is invoked by: Application.Run (new formClass ()); I'd like to put a try/catch around the whole thing to trap any uncaught exceptions. When I put it around this Run method, exceptions are not caught; control only returns here when the program terminates after an uncaught exception. Where can I put try/catch to cover the whole program? Thanks! 回答1: To catch Windows Form's unhandled exceptions hook-up the AppDomain.UnhandledException and Application.ThreadException events. Of