exception-handling

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

戏子无情 提交于 2019-12-08 03:06:06
问题 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? 回答1: The only potential problem is that you're catching a

Uncaught Exception Handling in JSF

≯℡__Kan透↙ 提交于 2019-12-08 02:52:00
问题 I am trying to create a filter to handle exceptions (see Handling Uncaught Exception in JSF) public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { log.info("check filter is running"); chain.doFilter(request, response); } catch (Exception e) { log.error("Uncaught exception",e); request.setAttribute("exception", e); request.getRequestDispatcher("/error.xhtml").forward(request, response); } } I execute the following

How to catch an exception thrown in ctypes?

自古美人都是妖i 提交于 2019-12-08 02:50:15
问题 I am working with some C code called from Python using ctypes. Somewhere in the bowels of the C library, an exception is occurring and/or abort() is being called. Is there any way I can catch this in my Python caller code? (Platform is Linux) 回答1: You might be able to setup a signal handler on SIGABRT to handle the signal caused by abort(). However, failed assertions might go along with corrupted memory and other bad things - there's usually a reason why an assertion failed. So usually

Linking Server Side Message/Exception with AJAX request

我是研究僧i 提交于 2019-12-08 02:39:50
问题 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

How to gracefully close a form if an exception occurs on that form in C#

偶尔善良 提交于 2019-12-08 02:11:38
问题 I am in a position where I have a large user app that has quite a few forms and I am looking for a way to close a single form if an exception has occurred due to some logic that has been caught on that form. Right now I am following the principal of 'don't write try/catch everywhere to catch boneheaded mistakes' and it does make my code cleaner, but causes crashes the entire app when I have a NullPointerException. The best solution would be a 'local error handler' that each form would have

ASP.NET – Error throwing or logging

删除回忆录丶 提交于 2019-12-08 01:24:30
问题 We are building an ASP.NET application in C# We have 3 layers: UI, Business and Database. We need clarification on error handling/logging. We have a error logging framework to log errors. My question is: do we need to log errors in each layer or only in the main calling layer (UI layer) by throwing the errors to UI layer from business and database layers? Is there a best practice? If would be great if you could also provide a reference document or web references (If needed). Thanks and

Spring return JSON for HTTP 406 (NOT_ACCEPTABLE)

拈花ヽ惹草 提交于 2019-12-08 01:06:39
问题 Spring allows the definition of @ExceptionHandlers inside of @RestControllerAdvice . I already defined a lot of other ExceptionHandlers in there for HTTP 400, 404, 405,... However the ExceptionHandler for HTTP 406 (NOT_ACCEPTABLE) does not seem to work. The handler is triggered, I checked that in the logs, but the result is not used. My goal is it to return a HTTP 406 with a JSON body. Variant 1 @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) @ExceptionHandler(HttpMediaTypeNotAcceptableException

How do identify STATUS_INVALID_CRUNTIME_PARAMETER exception

巧了我就是萌 提交于 2019-12-08 00:55:47
问题 Platform is Windows 7 SP1. I recently spent some time debugging an issue that was caused because a code was passing an invalid parameter to one of the "safe" CRT functions. As a result my application was aborted right away with no warning or anything -- not even a crash dialog. At first, I tried to figure this out by attaching Windbg to my application. However when the crash happened, by the time the code broke into Windbg pretty much every thread had been killed save for ONE thread on which

Exception handler for REST controller in spring

允我心安 提交于 2019-12-07 23:46:09
问题 I want to handle exceptions so the URL information is automatically shown to the client. Is there an easy way to do this? <bean id="outboundExceptionAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver"> <!-- what property to set here? --> </bean> 回答1: You have two choices: Spring Reference 15.9.1 HandlerExceptionResolver Spring HandlerExceptionResolvers ease the pain of unexpected exceptions that occur while your request is handled by a

try catch bad form?

混江龙づ霸主 提交于 2019-12-07 23:29:36
问题 i think i sort of know the answer to this, but there are always many ways to do things (some of which are clearly wrong :) )... I have a little recursive function to find an employees manager's id. this is being used in a import script and it may be that the persons immediate manager has left (been disabled) so we need to find that employees (the manager) manager (and so on) so we can assign stuff to them. in case it isn't obvious, the EmployeesToDisable is a generic list of employees that