You searched for exceptions. We found 168 results in 0.056 seconds.

Can initializer block throw exception?

I am using BufferedReader in a class to read from a file. I am trying to initialize this in initializer block. class ReadFromFile { BufferedReader br; { br =...
Jon Skeet
people
quotationmark

An initializer block can only throw unchecked exceptions, or checked exceptions which are declared to be thrown by all constructors. (This includes exceptions which are subclasses of those which are declared.) You can't throw a checked... more

people

Async/await exception and Visual Studio 2013 debug output behavior

I'm developing an application in C# that communicates with Dynamics NAV through web services. To reduce duplicate code and because there will be many endpoints, I have created a...
Jon Skeet
people
quotationmark

When an exception occurs in an async method, it doesn't just propagate up the stack like it does in synchronous code. Heck, the logical stack is likely not to be there any more. Instead, the exception is stored in the task which... more

people

I can't read a compressed file

We have to write a compressed file first with DeflaterOutputStream and than we have to read it back with the InflaterInputStream. I always get an EOFException when i try to read...
Jon Skeet
people
quotationmark

You have three problems here: You're using a PrintStream for no reason, and that will swallow exceptions. You're writing data using an ObjectOutputStream, i.e. creating a binary file of Java serialized objects, but you're trying to read... more

people

What exception to throw "Wrong Scenario" (Java)

This is a silly question - but it bugs me. From the existing (library) Java exceptions, which should I throw in the following. I have a method that is used in the wrong scenario...
Jon Skeet
people
quotationmark

I have a method that is used in the wrong scenario (it's basic assumption doesn't hold). That sounds like an exact match for IllegalStateException: Signals that a method has been invoked at an illegal or inappropriate... more

people

Getting error while using a throws clause with an overriding method in java?

I am getting a error when i am using a throw clause with the method demo().And i want to know that what are the limitations of using throws in inheritance. The error is:...
Jon Skeet
people
quotationmark

ClassNotFoundException is a checked exception - and you can't declare that a method override will throw any checked exceptions that the method it's overriding doesn't declare. From section 8.4.8.3 of the JLS: A method that overrides... more

people

Why can't I catch an exception from async code?

Everywhere I read it says the following code should work, but it doesn't. public async Task DoSomething(int x) { try { // Asynchronous implementation. await...
Jon Skeet
people
quotationmark

Your code won't even compile cleanly at the moment, as the x++; statement is unreachable. Always pay attention to warnings. However, after fixing that, it works fine: using System; using System.Threading.Tasks; class Test { static... more

people

Java Multi Catch/Rethrow

If I do the following using a multi-catch in Java 1.7: catch (ArrayIndexOutOfBoundsException | NullPointerException ex) { logger.error("Array out of bounds exception in...
Jon Skeet
people
quotationmark

Will the re-thrown exception maintain the exception type that originally entered the catch clause? Yes - it will rethrow the exact same exception object. You need to differentiate between the compile-time type of ex (which is... more

people

How can I verify an exception was thrown with a certain parameter?

Suppose I have the following exception and method: public MyException(string type) { /* Does soemthing with the parameter */ } public void DoSomething() { // ... if...
Jon Skeet
people
quotationmark

I'd usually go with [ExpectedException(typeof(MyException)] I suggest you don't do that. You haven't told us which unit test framework you're using, but these days most provide something like: Assert.Throws<MyException>(()... more

people

Importing Java packages and classes

I'm talking about the stuff we import. Suppose, there is something like: import java.util.Scanner; util is the package and Scanner is the class, right? Can this be always...
Jon Skeet
people
quotationmark

Can this be always generalised and be said that in the import statement, the first one would be java/javax (is there any other?), the second one package, the third class and the fourth, if any will always be a method belonging to the... more

people

What is a "localized message"?

I have seen in several languages that (especially exceptions) offer message and localised message methods. But it is not clear to me what the difference is - do any of the...
Jon Skeet
people
quotationmark

This one: Is this a physical location thing where the same message may be presented based on things like locale, timezone, etc. Although it's usually just locale / culture, really. Basically imagine that an error message of "The... more

people