exception-handling

@ExceptionHandler for Error gets called only if there's no mapping for Exception

泄露秘密 提交于 2019-12-06 02:23:49
Using spring-web-4.2.6, I have the following Controller and ExceptionHandler: @ControllerAdvice public class ExceptionsHandler { @ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> HandleDefaultException(Exception ex) { ... } @ExceptionHandler(InternalError.class) public ResponseEntity<ErrorDTO> HandleInternalError(InternalError ex) { ... } } @RestController @RequestMapping("/myController") public class MyController { @RequestMapping(value = "/myAction", method = RequestMethod.POST) public boolean myAction() { throw new InternalError(""); } } For some reason, the

C++ exception for null pointers

╄→гoц情女王★ 提交于 2019-12-06 02:08:09
问题 I have a little function (in a DLL) which looks like this: int my_function(const char* const s) { try { return my_object->do_something_with(s); } catch (exception& e) { return ERROR_CODE; } } I thought that the try-catch block would prevent anything which might happen inside my_object from propagating to the outside. Unfortunately, I was wrong, and my program which calls this function (from VB) just stopped working because I had passed a null pointer argument. So, why is my try-catch block

When catching a general exception, how can I determine the original exception type?

我是研究僧i 提交于 2019-12-06 01:57:18
问题 When catching an exception in .NET, you can have as many type-specific exception blocks as needed. But I usually try to have at least one "general" exception catch block. But is there a way to get the type of the "real" exception thrown that is caught by the generic exception handler, perhaps using reflection? For example, if I have Catch ex As System.ServiceModel.FaultException(Of InvalidUser) ProcessModuleLoadException(Me, ex) Catch ex As System.ServiceModel.FaultException(Of SQLExceptions)

Handle CursorLoader exceptions

社会主义新天地 提交于 2019-12-06 01:40:04
问题 I have a Fragment implementing LoaderManager and using CursorLoader (nothing fancy). I want to catch exceptions thrown during the query but I don't see how!!! Any help? Thx. 回答1: You would need to derive from CursorLoader to do it. Something like this: class MyCursorLoader extends CursorLoader { public MyCursorLoader(Context context) { super(context) } public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { super(context

How to return “already exists” error in Flask-restless?

拜拜、爱过 提交于 2019-12-06 01:31:23
问题 I would like to do some handler for exception. I'm using a combination of Flask-restless and SQLAlchemy in python. My problem: When I send request to api with object that already exists in DB, SQLAlchemy shows exception: IntegrityError: (IntegrityError) column <column_name> is not unique u'INSERT INTO ... So I have tried to add attribute validation_exceptions into create_api method: manager.create_api( ... , validation_exceptions=[IntegrityError]) But response json contains: { "validation

Can someone explain exactly what happens if an exception is thrown during the process of allocating an array of objects on the heap?

荒凉一梦 提交于 2019-12-06 01:23:48
I defined a class foo as follows: class foo { private: static int objcnt; public: foo() { if(objcnt==8) throw outOfMemory("No more space!"); else objcnt++; } class outOfMemory { public: outOfMemory(char* msg) { cout << msg << endl;} }; ~foo() { cout << "Deleting foo." << endl; objcnt--;} }; int foo::objcnt = 0; And here's the main function: int main() { try { foo* p = new foo[3]; cout << "p in try " << p << endl; foo* q = new foo[7]; }catch(foo::outOfMemory& o) { cout << "Out-of-memory Exception Caught." << endl; } } It is obvious that the line "foo* q = new foo[7];" only creates 5 objects

Rethrow php exception into higher level catch block

你。 提交于 2019-12-06 01:16:29
问题 I am trying to pass an exception from a specific catch block to a more general catch block. However it does not appear to be working. I get a 500 server error when I try the following. Is this even possible? I realize that there are easy workarounds, but isn't it normal to say, "Hey I don't feel like dealing with this error, let's have the more general exception handler take care of it!" try { //some soap stuff } catch (SoapFault $sf) { throw new Exception('Soap Fault'); } catch (Exception $e

Why is the ArrayStoreException a RuntimeException?

佐手、 提交于 2019-12-06 01:08:30
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 of object into an array of objects. I've read here that When array is created it remembers what type

Handle global exceptions in VB

流过昼夜 提交于 2019-12-06 01:05:13
问题 Hello I have this project experiencing some problems with what is supposed to be my codes for the "problem" handler. Public Event UnhandledException As UnhandledExceptionEventHandler Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim currentDomain As AppDomain = AppDomain.CurrentDomain AddHandler currentDomain.UnhandledException, AddressOf MyHandler End Sub Sub MyHandler(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)

Exception handling in rxjava

大憨熊 提交于 2019-12-06 00:48:34
I am trying to get accustomed to rxjava and I am trying to call the below QuoteReader in an Observable. I am not sure how to handle the exception thrown, public class QuoteReader { public Map<String, Object> getQuote() throws IOException{ OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder().url("http://quotes.rest/qod.json").build(); Gson gson = new Gson(); Map<String, Object> responseMap = null; try(Response response = okHttpClient.newCall(request).execute()) { responseMap = gson.fromJson(response.body().string(), Map.class); System.out.println("response map