exception-handling

Why is the ArrayStoreException a RuntimeException?

[亡魂溺海] 提交于 2019-12-07 12:02:55
问题 Let's say we have the following program: class Fruit {} class Apple extends Fruit {} class Jonathan extends Apple {} class Orange extends Fruit {} public class Main { public static void main(String[] args) { Fruit[] fruit = new Apple[10]; try { fruit[0] = new Fruit(); // ArrayStoreException fruit[0] = new Orange(); // ArrayStoreException } catch(Exception e) { System.out.println(e); } } } Based on the Java documentation: Thrown to indicate that an attempt has been made to store the wrong type

AppDomain.UnhandledException handler doesn't fire in unit test

放肆的年华 提交于 2019-12-07 11:16:16
问题 In the code snippet below, why wouldn't the attached handler (of AppDomain.CurrentDomain.UnhandledException event) fire up when an exception is thrown in the unit test? I'm using NUnit 2.5.10 with TestDriven.NET 3.0 on VS2010. [TestFixture] public class MyTests { private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("Gotcha!"); } [Test] public void ExceptionTest1() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain

Getting the Exception object in a try..catch to include FULL stacktrace, currently its truncated

不羁的心 提交于 2019-12-07 10:58:38
问题 can anyone help? I am trying to get the full stacktrace when within a catch of try..catch. Currently its truncated to include only the current method where the error is.... Let me explain.. Currently i my stacktrace includes the method "Third" where the error happens but First and Second isn't included, i believe this is by design. private void First() { this.Second(); } private void Second() { this.Third(); } private void Third() { try { throw new SystemException("ERROR HERE!"); } catch

Spring MV 3.2 Exception Response Mapping

时光怂恿深爱的人放手 提交于 2019-12-07 10:45:15
问题 Spring 3.2.15, MVC-based REST API here ( not Spring Boot, sadly!). I am trying to implement an exception mapper/handler that meets the following criteria: No matter what happens (success or error), the Spring app always returns a response entity of MyAppResponse (see below); and In the event of processing a request successfully, return an HTTP status of 200 (typical); and In the event of processing a request and an exception occurs, I need to control the mapping of the specific exception to a

application level global exception handler didn't get hit

十年热恋 提交于 2019-12-07 10:25:12
问题 My .net application has a global exception handler by subscribing to AppDomain.Current.Domain UnhandledException event. On a few occassions i have seen that my application crashes but this global exception handler never gets hit. Not sure if its help but application is doing some COM interop. My understanding is that as long as I don't have any local catch blocks swallowing the exception, this global exception handler should always be hit. Any ideas on what I might be missing causing this

Python: Catching an exception works outside of a function but not inside a function

℡╲_俬逩灬. 提交于 2019-12-07 08:50:25
I have a strange problem which I can't solve myself. If I execute outside_func.py in two separate terminals, the second execution catches the BlockingIOError exception and the message is printed: outside_func.py import fcntl import time # Raise BlockingIOError if same script is already running. try: lockfile = open('lockfile', 'w') fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) except BlockingIOError: print('Script already running.') time.sleep(20) If I do the same with inside_func.py nothing is caught and no message is printed: inside_func.py import fcntl import time # Raise

Getting sensible info from CLR-to-SEH exceptions in a mixed mode C++ project

戏子无情 提交于 2019-12-07 08:42:44
问题 Mixed mode C++ project. Native code is calling managed code. Managed code might throw an exception. I can catch said exception in native mode using a vectored exception handler; I can see its PEXCEPTION_POINTERS . The telling code 0xE0434F4D, meaning it's a CLR exception, is there. Question: is there any way to get any sensible information (exception class, message, stack trace etc.) from the attendant data? There's one parameter in the ExceptionInformation , and it looks like a pointer to

In C# (or .NET in general) can you mask the call stack level where an exception was thrown via attributes?

痴心易碎 提交于 2019-12-07 08:11:33
问题 The title may be a little confusing so I'll explain. Say you had this call chain... public DoWork(index) >> private DoWorkHelper(index) >> private CheckIndex(index) Now if you call DoWork , it traverses the calls down to CheckIndex , adding each deeper call to the call stack. Now if someone calls DoWork with a bad value for index , it throws the exception all the way down at CheckIndex , and currently, that's where the debugger breaks. You then have to walk back up the call stack to see the

Java/Spring > Handle Bad Request response for controller method with @RequestBody when no body is sent in request

妖精的绣舞 提交于 2019-12-07 07:54:26
long story short: I'm creating API that is supposed to be 100% REST. I'm trying to overwrite default response for the following case: I've got a method in my @RestController that has @RequestBody as an attribute @RequestMapping(value = {"register"}, method = RequestMethod.POST, produces = "application/hal+json") public Resource<User> registerClient(@RequestBody User user, HttpServletRequest request) and the method is working just fine if I send a proper request. But there is a problem when I don't. When a request has empty body, I get a generic Tomcat error page for status 400 and I need it to

Navigation from managed bean constructor in ADF Faces JSF 1.2

放肆的年华 提交于 2019-12-07 07:33:35
问题 Is it possible to navigate to another page/view from the constructor of the managed bean? I want this redirection if any exception occurred. I have tried many ways: Try-1: getFacesContext().responseComplete(); getFacesContext().getApplication().getNavigationHandler().handleNavigation(getFacesContext(), null, "gotoPartError"); getFacesContext().renderResponse(); Try-2: getServletResponse().sendRedirect("partError.jspx") Try-3: getFacesContext().responseComplete(); getFacesContext()