exception-handling

error occurred while updating the object context

♀尐吖头ヾ 提交于 2019-12-05 08:20:47
first of all here is the message The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship. the problem happens when i try to insert new data in the entityframework My entity model in the database i set the relation to cascade on delete and update. that is the only change

@ControllerAdvice exception handler method not get called

人盡茶涼 提交于 2019-12-05 08:03:58
I am working on sample demo application for Exception Handling in Spring MVC.I am trying Exception Handling With @ControllerAdvice I followed steps as describe in this link. But when i run my application i get the following error org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.test.core.ApplicationException For more details following are the classes I am working on ApplicationException.java public class ApplicationException extends RuntimeException{ /** * */ private static final long serialVersionUID = -9061684361606685158L; private

How to avoid many try catch blocks in java

主宰稳场 提交于 2019-12-05 07:54:45
I'm very new to java and the idea of try catch blocks to handle exceptions. This roughly what I'm ending up with, and there simply has to be a better way: try { JSONObject jsonObject = new JSONObject(jsonString); int aCount = jsonObject.getInt("acount"); String devTok = jsonObject.getString("dt"); String qURL = jsonObject.getString("qu"); try { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key qKey = KeyFactory.createKey("qu", qURL); int dsACount = (Integer) datastore.get(qKey).getProperty(kLastKnownANumber); //..etc.. more try catch blocks needed } catch

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

▼魔方 西西 提交于 2019-12-05 07:53:15
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.MyExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">message</prop>

Core Data: solve a strange EXC_BAD_ACCESS error

断了今生、忘了曾经 提交于 2019-12-05 07:32:23
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 ModelA instance I have about 200 instances of ModelB . I use a code like this: ModelB *model =

Try catch exception handling C++

混江龙づ霸主 提交于 2019-12-05 07:14:33
问题 I have just started with exception handling in C++ using try and catch blocks. I have a text file with some data and I am reading this file using ifstream and getline as shown below, ifstream file; file.open("C:\\Test.txt", ios::in); string line; string firstLine; if (getline(file, line, ' ')) { firstLine = line; getline(file, line); } I would like to know how to implement exception handling in case file.open fails to open the specified file because it does not exist in the given path, for

Ruby - Execution expired

拜拜、爱过 提交于 2019-12-05 07:09:18
I have a ruby code like this: begin doc = Nokogiri::HTML(open(url).read.strip) rescue Exception => ex log.error "Error: #{ex}" end And I am getting log as: ERROR -- : Error: execution expired I want block re-execute until it success. How can I do it? I'll expand on my comment a little bit. You can use retry to go back to the begin : begin doc = Nokogiri::HTML(open(url).read.strip) rescue Exception => ex log.error "Error: #{ex}" retry end That will keep trying (and logging errors) until it works or you manually kill it. That's probably not what you want though as one little mistake will send

.NET Catch General Exceptions

浪尽此生 提交于 2019-12-05 06:38:21
.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 " + classname + "\n" + ex.Message); } } return obj; } In the following code I catch particular exceptions but not

Exception Handling with Scanner.nextInt() vs. Scanner.nextLine()

允我心安 提交于 2019-12-05 06:29:39
问题 This question is solely for educational purposes. I took the following code from a textbook on Java and am curious why input.nextLine() is used in the catch block. I tried to write the program using input.nextInt() in its place. The program would no longer catch the exception properly. When I passed a value other than an integer, the console displayed the familiar "Exception in thread..." error message. When I removed that line of code altogether, the console would endlessly run the catch

How to handle all errors, including internal C library errors, uniformly

天大地大妈咪最大 提交于 2019-12-05 06:14:46
问题 I wanted to handle all internal errors gracefully, without program termination. As discussed here, using _set_se_translator catches divide-by-zero errors. But it does not catch, for example, C runtime library error -1073740777 (0xc0000417) , which can be caused by format strings for printf which have the percent sign where they shouldn't. (That is just an example; of course we should check for such strings). To handle these, _set_invalid_parameter_handler is needed. There are about ten other