exception-handling

@ExceptionHandler for all controllers in spring-mvc

六眼飞鱼酱① 提交于 2019-12-07 16:29:28
问题 I have wrote following controller to handle all exception in my code: @Controller public class ErrorHandlerController { @ExceptionHandler(value = Exception.class) public String redirectToErrorPage(Model model){ model.addAttribute("message", "error on server"); return "errorPage"; } } But looks like following exception handler will work only if exception throws inside ErrorHandlerController I have a huge count of controllers. Please advice me how to write one ExceptionHandler for all

Exception handling with get_meta_tags() & get_headers()?

你。 提交于 2019-12-07 15:06:32
问题 In PHP, I am using get_meta_tags() and get_headers() , however, when there is a 404, those two functions throw a warning. Is there any way for me to catch it? Thanks! 回答1: get_headers does not throw a Warning/Error on 404, but get_meta_tags does. So you can check the header response and do something, when it's not OK: $url = 'http://www.example.com/'; $headers = array(); $metatags = array(); $validhost = filter_var(gethostbyname(parse_url($url,PHP_URL_HOST)), FILTER_VALIDATE_IP); if(

What is the correct way to configure custom mapper for WebApplicationException?

让人想犯罪 __ 提交于 2019-12-07 14:47:59
问题 I've created class that implements implements ExceptionMapper<WebApplicationException> and registered it by environment.addProvider(new WebApplicationExceptionMapper()); . My custom mapper works but only for some exceptions extended from WebApplicationException . For example it doesn't work for ConflictException and it also doesn't work for my custom exceptions with following constructor: public ConflictException(URI location, Object entity) { super(Response.status(Response.Status.CONFLICT)

Catching errors when logging with SocketHandler in Python

折月煮酒 提交于 2019-12-07 14:31:53
问题 My web application runs on multpile apache instances and I am having multiprocess logging issues because of this. I am currently using a SocketHandler for logging to a daemon using SocketServer that then writes logs to a single log file (similar to this example). Now that I am using a SocketHandler for logging I am having trouble discovering if/when the socket server crashes. For example, if I try creating a SocketHandler for a port that has no listening socket server, no exception arises. I

How to avoid triggering an ArrayIndexOutOfBoundsException while parsing empty positions in a line of CSV?

血红的双手。 提交于 2019-12-07 14:16:26
String[] values = line.split(","); Long locId = Long.parseLong(replaceQuotes(values[0])); String country = replaceQuotes(values[1]); String region = replaceQuotes(values[2]); String city = replaceQuotes(values[3]); String postalCode = replaceQuotes(values[4]); String latitude = replaceQuotes(values[5]); String longitude = replaceQuotes(values[6]); String metroCode = replaceQuotes(values[7]); String areaCode = replaceQuotes(values[8]); //... public String replaceQuotes(String txt){ txt = txt.replaceAll("\"", ""); return txt; } I'm using the code above to parse a CSV with data in this format:

.net Attributes that handle exceptions - usage on a property accessor

时间秒杀一切 提交于 2019-12-07 13:53:24
问题 well I know from my asp.net mvc experience that you can have attributes that handle exceptions (HandleErrorAttribute). As far as I can tell the Controller class has some OnException event which may be integral to this behaviour. However, I want to do something similar in my own code: dream example: public String MyProperty { [ExceptionBehaviour(typeof(FormatException), MyExEnum.ClearValue)] set { _thing.prop = Convert.ToThing(value); } } .... The code above obviously makes very little sense,

Exception handling in rxjava

こ雲淡風輕ζ 提交于 2019-12-07 13:08:50
问题 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(

Handle Socket.ReceiveFrom with timeout without spamming console

梦想与她 提交于 2019-12-07 13:06:42
问题 I am writing a ServerLocator that basically broadcast a port to find a server which will respond with an IPEndPoint and I need the search to be able to timeout if nothing is found on the current IPHost and then move on with the next one. Right now I am doing something like this (I have removed some parts of this code so it only includes what is needed to display my problem. There is also some client bindings going on here) string serverIp = string.Empty; while(string.isNullOrEmpty(serverIp))

How to rescue from a OAuth::Unauthorized exception in a Ruby on Rails application?

跟風遠走 提交于 2019-12-07 13:04:57
问题 How can I rescue from an OAuth::Unauthorized exception as raised from OmniAuth in a Ruby on Rails application? Obviously this: rescue_from OAuth::Unauthorized, :with => :unauthorized won't work as that only catches exception thrown inside Rails and this exception is thrown somewhere else in the rack chain. In this application the administrators (and not us, the developers) configure the credentials for twitter and facebook, so having the wrong ones is something that can happen and indeed does

Returning JSON error when catching Django exception?

时间秒杀一切 提交于 2019-12-07 12:16:22
问题 Does anyone have opinions on the best way of having middleware catch exceptions, and instead of rendering the error into a HTML template, to return a JSON object? Currently I have the middleware below that catches exceptions, and if it can find an extra user error message, puts that onto the request (that the template then picks up). class ExceptionUserErrorMessageMiddleware(object): def process_exception(self, request, exception): """ if the exception has information relevant to the user,