exception-handling

Access exception.class.name in spring:message tag when using SimpleMappingExceptionResolver

让人想犯罪 __ 提交于 2019-12-07 03:13:06
问题 In several previous projects (all pre-Spring 3.0), I had a single error handling jsp file (usually "message.jsp") that had a line similar to the following: <spring:message code="exceptions.${exception.class.name}" text="${exception.message}"/> This allowed me to map exceptions to this page and resolve certain localized error messages based on the exception type by defining a derivative of the SimpleMappingExceptionResolver: <bean id="exceptionMapping" class="mycode.ui.resolvers

Core Data: solve a strange EXC_BAD_ACCESS error

本秂侑毒 提交于 2019-12-07 03:07:52
问题 I am facing a really strange problem with Core Data. Let's describe it: Definitions Let's say I have two models, ModelA and ModelB . In the data model ModelA has a reference to ModelB as a one-to-many association, and consequently ModelB has a one-to-one association with ModelA . Update When the application launches (especially at first launch), or when the user asks, I have to create or update all the ModelB instances for each ModelA instance. ModelA instances are predetermined. For each

.NET Catch General Exceptions

社会主义新天地 提交于 2019-12-07 02:49:14
问题 .NET Programming guidelines state that we should not catch general exceptions. I assume the following code is not very good because of the general exception type catch: private object CreateObject(string classname) { object obj = null; if (!string.IsNullOrEmpty(classname)) { try { System.Type oType = System.Type.GetTypeFromProgID(customClass); obj = System.Activator.CreateInstance(oType); } catch (Exception ex) { Log.Error("Unable to create instance for COM Object with class name " +

NodeJS Server with mysql hangs

落爺英雄遲暮 提交于 2019-12-07 02:35:43
问题 I am writing an application using NodeJS, Express, mysql, so far everything works fine, but when I run my application after sometime when mysql connection is interrupted my application throughs this exception and my application goes down. Error: read ECONNRESET at errnoException (net.js:901:11) at TCP.onread (net.js:556:19) From another stackquestion i came to know that i have to handle such uncaught exceptions like this. process.on('uncaughtException', function(err) { console.log('Caught

Catch a fatal exception and continue

人盡茶涼 提交于 2019-12-07 02:04:30
问题 I know, that by its very definition, a fatal exception is supposed to kill the execution, and should not be suppressed, but here's the issue. I'm running a script that scrapes, parses and stores in a DB about 10,000 pages. This takes a couple of hours, and in rare cases (1 in 1000) a page fails parsing and throws a fatal exception. Currently, I'm doing this: for ($i=0;$i<$count;$i++) { $classObject = $classObjects[$i]; echo $i . " : " . memory_get_usage(true) . "\n"; $classDOM = $scraper-

Approaches for Error Code/Message Management in .NET

梦想的初衷 提交于 2019-12-07 01:04:03
问题 Looking for suggestions/best practices on managing error codes and messages in a multi-tiered applications. Specifically things like: Where should error codes be defined? Enum? Class? How are error messages or further details associated with the error codes? resource files? attributes on enum values, etc.? If you have a multi-tier application consisting of DAL, BLL, UI, and Common projects for example, should there be a single giant list of codes for all tiers, or are the codes extensible by

Best way to handle errors when opening file

这一生的挚爱 提交于 2019-12-07 00:40:30
Handling files (opening) is an activity particularly prone to error. If you were to write a function to do this (although trivial), what is the best way to write it in wrt handling errors? Is the following good? if (File.Exists(path)) { using (Streamwriter ....) { // write code } } else // throw error if exceptional else report to user Would the above (although not syntactially correct) a good way to do this? First you can verify if you have access to the file, after, if the file exists and between the creation of the stream use a try catch block, look: public bool HasDirectoryAccess

How to handle exceptions in Parallel.Foreach?

半世苍凉 提交于 2019-12-07 00:05:31
问题 I have a parallel.Foreach loop in my code and I am wondering how to handle exceptions. Should I catch and handle(e.g write to log) exceptions inside the loop or should I catch aggregate exception outside - encapuslate the loop in try/catch? Best regards 回答1: Should I catch and handle exceptions inside the loop or should I catch aggregate exception outside Those two are not functionally equivalent. Both can be done, and in different ways. But the more fundamental question is: when one or more

Get google test exception throw message [duplicate]

三世轮回 提交于 2019-12-06 22:25:52
问题 This question already has an answer here : Verifying exception messages with GoogleTest (1 answer) Closed 4 years ago . I am using google Test framework for my project. I am throwing exception from the code as: throw DerivedClassException("message"); and in the test frame using as: ASSERT_THROW(commond(), DerivedClassException); I want to get message with what() API. Any way to get exact exception message of the exception. 回答1: The only way to check the thrown exception is to catch it in the

Is there a way to Wait for a TPL Task without in throwing an exception?

爱⌒轻易说出口 提交于 2019-12-06 22:23:08
问题 Some of us prefer to code in an exception-light style. However, if you wait for a Task Parallel Library task, and the task threw an exception, it will throw an exception on the calling thread as well. Is there a (preferably standard) way to avoid this behaviour and just check the response for exceptions when you get it back? 回答1: You can use Task.WaitAny like: var task = Task.Run(() => { // ... throw new Exception("Blah"); }); Task.WaitAny(task); if (task.IsFaulted) { var error = task