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

Java: handle exception and return result from inner method

Question: How to do both: handle exception in outer method and return result of inner method? I have: two methods which return List: import java.util.List; import...
Jon Skeet
people
quotationmark

No - the inner method doesn't return anything, because it throws an exception instead. The outer method simply doesn't have a result to work with. If a method throws an exception, it's generally expected that none of the work in the... more

people

Can I recursively call an async function without overflowing the stack?

Since the return site of the async function isn't the caller, I assume this works, but thought I'd verify that this was safe just in case. If it's not, why would this overflow the...
Jon Skeet
people
quotationmark

The reason it's working for you is not because of the way CheckAsync is called, but because you're awaiting the result of Task.Delay. That will always return a "not completed yet" task, so awaiting it will schedule a continuation. That... more

people

Why does this method keep returning dynamic despite the return type in the signature?

So the type being returned by the activator (not shown here) is just a POCO that I created. Nothing special about it at all. But despite, the return type of GetWrapper or...
Jon Skeet
people
quotationmark

I strongly suspect that either child1 or child1.kind are of type dynamic, meaning that the expression is deemed to be a dynamically-bound expression, despite everything else. Here's a short but complete example to demonstrate what I... more

people

Passing dynamic object to C# method changes return type

I created a class that inherits DynamicObject and want to create a static method that can create new instances with pre-determined properties (stored in the Dictionary). public...
Jon Skeet
people
quotationmark

This is because almost any operation involving a dynamic value is resolved dynamically at execution time. There are no exceptions made for cases where actually there's only one method present at compile-time; the language is simpler that... more

people

Exception Handling: User Defined Exception:

In the following code userexception class defined below is inheriting ApplicationException class. To my knowledge I know base keyword is used to pass the parameter, to parent...
Jon Skeet
people
quotationmark

Ignore exceptions here. All you're seeing is the equivalent of this: public class Parent { private readonly string message; public string Message { get { return message; } } public Parent(string message) { ... more

people

Cannot get this property name using this code and expression api

I have the following class and I need to get its property names: public class PMLButtonData { public int BackgroundColorID { get; set; } public...
Jon Skeet
people
quotationmark

The problem is the type of your expression tree - you're trying to represent a delegate of type Func<T, object>, and if the property returns an int, that means it would need to be converted. You just need to make the method generic... more

people

Why upcasting can be done directly in c#, but in order to downcast we require expilicit casting?

Consider two simple classes public class Parent { public void ShowData() { } } public class Child : Parent { public void GetData() { } } // Upcasting...
Jon Skeet
people
quotationmark

Why UpCasting does not require explicit casting ? Because it's always safe. It's never going to throw an exception. Why DownCasting requires explicit casting ? Because it's not safe. It can throw an exception, or lose... more

people

Overriding the message of exception in C#

Is there a way to override the message of an exception? I don't want to make a custom exception but to override the message of an existing exception. For example: Every time when...
Jon Skeet
people
quotationmark

For exceptions you're throwing, you can just pass the message in to the constructor: throw new ArgumentOutOfRangeException("name", "My custom message"); Note that here, name is the name of the parameter that caused the problem. In C# 6,... more

people

check if record exists in database using LINQ

I am getting a cast error here but I do not understand as to why. protected bool isPlayerdb(string userName) { try { Users adminUsers = from users in...
Jon Skeet
people
quotationmark

You're asking to assign a sequence value to single entity variable. That's like trying to do this: // Won't work for the same reason string name = new List<string> { "foo", "bar" }; If you're just trying to find out whether there... more

people

Method can only be called again if 3 seconds is passed

I want to implement some way to prevent a method from being called several times instantly. for example imagine if I have a class like: class Example { public void...
Jon Skeet
people
quotationmark

I don't see any need to use a timer here. You can use a Stopwatch: class Example { private static readonly TimeSpan MinInterval = TimeSpan.FromSeconds(3); private readonly Stopwatch stopwatch = new Stopwatch(); // Stopped... more

people