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

Exception InInitializer Error for public static integer

I have a code where I need to call number of Jobs as public static integers from Size.txt file as follows: public class GetJobs { public static int Jobs = valueN(), inp = 4; ...
Jon Skeet
people
quotationmark

This is the problem: public static int Jobs = valueN(), inp = 4; ... public static int valueN(){ ... int[] MN = new int [inp]; ... n=MN[0]; } When you run valueN(), inp is still 0. The initialization which will set inp... more

people

Why is the ArrayStoreException a RuntimeException?

Let's say we have the following program: class Fruit {} class Apple extends Fruit {} class Jonathan extends Apple {} class Orange extends Fruit {} public class Main { ...
Jon Skeet
people
quotationmark

If the array remembers what type of data it contains, it means that it KNEW the type of data it contains. At execution time, yes... just like at execution time, the type of an object is known: Object x = "foo"; // The compiler won't... more

people

What is the need of finally block when we can close files and all in catch block

What is the need of finally block when we can close files and all in catch block. Whatever thing we are closing or clearing in finally block can it be done in catch block. Please...
Jon Skeet
people
quotationmark

You normally want to perform the same clean-up action whether an exception is thrown or not. Doing that just with catch blocks is painful - especially if you want to make sure that you only call close() once, even if that throws. You'd end... more

people

Throw error. How can I fix this? I've tried many things, but I am new to it and the logic is a little beyond me

The line with "private static BufferedReader" is where the problem lies. "-unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown" is the...
Jon Skeet
people
quotationmark

The problem is more simply demonstrated like this: import java.io.*; class Test { private static Reader reader = new FileReader("foo.txt"); } The problem is that the static initializer for your class can throw an exception. That's... more

people

What effect does including async in signature (without await in body) have on program flow?

General question I've just tracked down a strange behaviour to the the absence of an async modifier in the signature of a method. With it, I get the expected behaviour, but...
Jon Skeet
people
quotationmark

My question is: what is async really doing when there isn't an await? In terms of observable behaviour: The code will still run synchronously, as the warning says The result (including any exception thrown) will be wrapped up in a... more

people

Why compiler and run time assuming the string return type as dynamic?

In C# 5 and VS 2017, I have, var json = JsonConvert.SerializeObject(items); // why json is dynamic here Clearly, SerializeObject returns string then why json is dynamic type...
Jon Skeet
people
quotationmark

Clearly, SerializeObject returns string then why json is dynamic type instead of string. Almost every operation involving a dynamic value is considered to be dynamic in turn. This includes method calls and most operators. The only... more

people

virtual List<T> :“The function evaluation requires all threads to run”

I am following the following tutorial to learn code fast. Code First to a New Database I have done till the step 4: of the tutorial, the problem arises when i try to run my code....
Jon Skeet
people
quotationmark

The exception message shows that you've used Blog and Post as classes nested within Program, whereas the instructions state: Below the Program class definition in Program.cs add the following two classes. Personally I'd put them into... more

people

Trying to understand method signature changes spanning assemblies

We ran into a strange problem with a promotion and I'm hoping I'll be able to explain it with code. I want to understand why it behaves in the manner it is. Assembly 1 public...
Jon Skeet
people
quotationmark

Why does the compiled code on assembly 2 change based on a method signature that (at least I think) should be transparent? No, it shouldn't. When you don't specify an argument to correspond with an optional parameter, the default... more

people

Use of unassigned local variable in a Try Catch

It seems that this particular error has been solved quite a few times but my code snippet has something different in that it will never cause an "unassigned" error. This code is...
Jon Skeet
people
quotationmark

my code snippet has something different in that it will never cause an "unassigned" error Well it clearly does cause that error, which is why you asked the question, no? Even though you know that any time the exception is thrown,... more

people

Good practice throw an exception to satisfy a function return

Built a custom IDataReader which goes looking in XML for values that match particular element names and, if found, returns the values. The GetValue function - which has to return...
Jon Skeet
people
quotationmark

Well unless you really need the catch block, you don't need to introduce try/catch/finally. You can just add a throw statement at the end of your initial method. Along the way, I'd start using FirstOrDefault(), follow normal C# naming... more

people