exception-handling

Developer Exception Page is blank if added to IApplicationBuilder after MVC

删除回忆录丶 提交于 2019-12-10 23:27:17
问题 Developer Exception Page ( app.UseDeveloperExceptionPage() ) is blank if added to IApplicationBuilder after MVC ( app.UseMvc() ) in Startup.cs Configure method. Developer Exception Page works fine if added before MVC. Is this behavior intentional or am doing something wrong? Visual Studio Code 0.10.6 on Mac Microsoft.AspNet.Diagnostics 1.0.0-rc1-final Microsoft.AspNet.Mvc 6.0.0-rc1-final DNX Mono 1.0.0-rc1-update1 回答1: The behavior you're seeing is TOTALLY intentional : in ASP.NET 5,

Can't rescue YAML.load exception

ε祈祈猫儿з 提交于 2019-12-10 23:07:16
问题 I'm trying to handle loading invalid YAML data in Ruby, but seem to be unable to rescue exceptions raised by psych. This is some example code to demonstrate the issue I'm having: require 'yaml' begin YAML.load('&*%^*') rescue puts "Rescued" end And the exception: # ruby test.rb /usr/lib64/ruby/1.9.1/psych.rb:203:in `parse': (<unknown>): did not find expected alphabetic or numeric character while scanning an anchor at line 1 column 1 (Psych::SyntaxError) from /usr/lib64/ruby/1.9.1/psych.rb:203

Checked exception specification and strategy pattern

梦想的初衷 提交于 2019-12-10 22:42:19
问题 I am a c++ developer and I am pretty new with the checked and unchecked exception in java. The exception specifications in c++ are simply not good and that's why nobody is using it. I like the checked exception and I have a question, let's have this interface: public interface Warehouse { MyStuff fetch(int id); } The warehouse can be implemented in different way: file, database or in memory (mock object for test). Now, if I want to implement using a file, I cannot try to open the file in the

Why would I extend java.lang.RuntimeException

╄→尐↘猪︶ㄣ 提交于 2019-12-10 22:39:59
问题 I was recently asked a question, apparently in an Interview, about extending the java.lang.RuntimeException. I was asked to cite an example where there would be a need to extend the java.lang.RuntimeException. I always thought that we would not need to extend the RuntimeException, can anybody enlighten me? Thanks, SB 回答1: One layer's runtime exception is another layer's checked (and acted upon) exception. I can see containers e.g. servlet container; REPLs and/or anything top-level interpreter

Break at throw for exception that is caught

僤鯓⒐⒋嵵緔 提交于 2019-12-10 22:20:01
问题 In the VS debugger, un-caught exceptions result in the program breaking at the point the exception is throw (or near enough) and in a state that lets you look at all the stack frames and there local variables up to that point. Is there a way to get this same result (break at throw) but for an exception is caught at a particular point? I'm not interested in doing this for ALL exceptions or even all exception of a given type (that could get useless real quick) but if I could do it for a single

How to catch 404 (NotFoundException) without being depndant on a JAX-RS implemenation?

喜夏-厌秋 提交于 2019-12-10 21:43:58
问题 Typically one uses ExceptionMapper to catch exceptions, log them, return a customized error messages. However while JAX-RS provides an NotFoundException in its api, the implementations (Jeresy, CXF,...) provide their own NotFoundException (such as com.sun.jersey.api.NotFoundException ) which doesn't extends the JAX-RS one. Leaving us with the sole option of having in our code implementation specific imports. This makes it hard if one wants to switch implementations. Is there another way to do

Perl: Force stacktrace for “can't call method on undefined”

ぃ、小莉子 提交于 2019-12-10 21:35:33
问题 I'm using Perl and Catalyst as Web-Framework. How can I globally force a stacktrace if an exception like Can't call method "XXX" on an undefined value... is thrown? Suppose the following code in your Controller/Root.pm use DateTime; sub test :Local :Args(0) { my ( $self, $c ) = @_; my $now = DateTime->now(time_zone=>'local'); my $tmp = undef; my $throwing = $tmp - $now; #this will throw an exception! $c->res->body("OK"); } Opening http://localhost:3000/test throws of course the exception:

Asking user to enter the input again after he gives a wrong value for the Input. InputMismatchException?

点点圈 提交于 2019-12-10 21:31:57
问题 I have created the following class for Inputting a user's age and then displaying appropriate info in the console. On running this program , the console asks "Please Enter your Age : " If the user enters an Integer for eg: 25 , the executed class displays " Your age is : 25" in the console. If the user enters a non-integer number , the console displays: Age should be an Integer Please Enter your Age: But I am not able to enter anything through the keyboard when I place my cursor next to

Throw Exception or prevent it?

北城余情 提交于 2019-12-10 21:17:21
问题 The question is if it is prefered to Throw an exception or to prevent it from ever occurring. It is for a game project. IndexOutOfBoundsException vs. coding around it. I have a List<E> private Attribute<List> attributes; A method to get an item by index. public Attribute getAttribute (int index) { if (index < 0 || index >= attributes.size()) index = 0; return attributes.get(index); } In this case I am defaulting to the 1st element of the list. 回答1: Failing fast is generally a good idea: if an

Problems with windows service, blockingcollection, and Multithreading

筅森魡賤 提交于 2019-12-10 21:09:44
问题 My scenario: Windows Service .NET 4 I poll a database for entities. When new entities come in they are added to a BlockingCollection . In the service's OnStart I create a System.Threading.Tasks.Task whose job is to enumerate the BlockingCollection (using GetConsumingEnumerable() ). The problem I'm having is this: When an unhandled exception occurs in the task, I want the exception logged and the service stopped. I can't catch exceptions from the task unless I call Task.Wait() . If I call Task