exception-handling

How to handle exceptions when writing a library (not an application) - Java

风流意气都作罢 提交于 2019-12-06 06:20:13
问题 I'm currently writing an Java Wrapper for a RESTful web services API. I'm now trying to clean up some of the exception handling, and not sure what approach to take. This is a tool intended to be used by Java programmers, so I can't really handle it the same way I would with a end-user application. If I have a method (connection) that contains code that could throw exceptions, how do I get those exceptions to float up to the end-programmer? and is this even the way I should handle it,

ThreadAbortException vs graceful event handle exit in C#

喜夏-厌秋 提交于 2019-12-06 06:18:47
When aborting the execution of a thread I'm always doubting between a graceful exit with an event handler like this: int result = WaitHandle.WaitAny(handles); if (result = WAIT_FINALIZE) FinalizeAndExit(); and using the event to signal the thread it must terminate or just handling the ThreadAbortException to finalize the thread... try { // Main execution } catch(ThreadAbortException e) { // FinalizeAndExit(); } finally { } I'm usually inclined to use the ThreadAbortException approach since it can be handled but it is re-raised at the end of the catch block, and it also avoids the thread from

Throwing nested Exceptions from a catch block…is this wise?

走远了吗. 提交于 2019-12-06 06:16:38
I want to implement custom exception handling in my library so that I know where an exception occurred, so I am doing this: try { DoSomething(); } catch(Exception ex) { //LibraryException refers to any exception in the libraries exception hierarchy throw new LibraryException(ex.Message, ex); } Should this be avoided? Does it have any performance implications? What are the implications of catching, nesting and re-throwing exceptions? The only potential problem is that you're catching a non-specific Exception , so not conforming to the exception handling guidelines . One of the following would

Linking Server Side Message/Exception with AJAX request

▼魔方 西西 提交于 2019-12-06 06:15:59
I am making an ajax submit using Primefaces but I am having trouble linking my server side message with my ajax request. Supposed I have this button that calls an action. In my managed bean, do I need to raise an exception? How do I pass this message into my ajax request public void checkout(ActionEvent event){ if(expression){ throw new CustomException("Account balance is not enough!"); } } public class CustomException extends RuntimeException { public CustomException(String message) { super(message); } } How do I handle this case? Will my onerror javascript method be able to handle this? Also

private inheritance, friends, and exception-handling

徘徊边缘 提交于 2019-12-06 06:13:28
问题 When class A privately inherits from class B it means that B is a private base class subobject of A. But not for friends, for friends it is a public sububject. And when there are multiple catch handlers the first one that matches (that is, if the exception type can be implicitly converted to the handler's parameter type) is called. So will anyone explain to me why the following code does not work as I expect? Is this behavior intended by the standard or is this a MSVC bug? class A { }; class

Camel retry control with multiple exceptions

旧街凉风 提交于 2019-12-06 05:52:40
问题 Preface: I'm fairly new to Camel, and after digesting Camel in action as best as possible, I'm adapting it to a project I'm on. In this project, we have some rather complex error handling, and I want to make sure I can replicate this as we Camel-ize our code. On our project (as most) there are a set of Exceptions we want to retry and a set that we don't - but more specifically, there are a set that we want to retry more than others (not all recoverable errors can be treated the same). In this

RIA Services and FaultContract

╄→尐↘猪︶ㄣ 提交于 2019-12-06 05:48:32
问题 How can I use the FaultContract attribute with RIA Services so that I'll be able to pass additional information as part of an exception to Silverlight? 回答1: So I went hunting though the decompiled RIA Services code. It doesn't seem like it's possible to significantly alter the error info that is sent to the client. You are able to override the OnError() method in your DomainService, but this doesn't allow you to pass arbitrary information back, even if it's a custom exception type. The reason

Pl/SQL Nested Procedure Exception Handling

烂漫一生 提交于 2019-12-06 05:39:43
问题 This is a best practice question on error handling through multiple levels of PL/SQL procedures. I've looked at a few other questions to help me out, in particular this one. Currently, I have a program with Procedure 1, which calls Procedure 2, which calls Procedure 3. I'm trying to perform adequate error handling - but I'd like to output eventually the exact problem back to the application layer. I'm hoping to get some ideas on how I can do this efficiently and clearly. My current solution

Exceptions and Access Violations in Paint events in Windows

主宰稳场 提交于 2019-12-06 05:38:25
问题 After executing some new code, my C++ application started to behave strange (incorrect or incomplete screen updates, sometimes no screen updates at all). After a while we found out that the new code is causing an Access Violation. Strange enough, the application simply keeps on running (but with the incorrect screen updates). At first we thought the problem was caused by a "try-catch(...)" construction (put there by an overactive ex-colleague), but several hours later (carefully inspecting

Why do we need Error class?

混江龙づ霸主 提交于 2019-12-06 05:37:24
问题 We have Throwable class which is the base class for Error class (for unrecoverable errors) and Exception class(for recoverable errors) So, 1> we can throw an object that implement error class.(Although it doesn't make sense to implement Error class because we have Exception class to do the same thing..) 2> Java doesn't recommend to catch Error object.. So what is the need of Error object then? Cant the compiler implement it internally? Isn't it a mistake? 回答1: Technically, the distinction is