tagged [exception]

What's the use of a finally block preceded by a catch-all catch block, in C#?

What's the use of a finally block preceded by a catch-all catch block, in C#? Consider the following C# code structure (S0-S3 are placeholders for arbitrary code blocks): In the case that S1 throws an...

11 Jan at 12:18

Exception handling loop puzzle

Exception handling loop puzzle I recently encountered a behavior that I've never seen before. I cannot quite understand what's going on most likely due to lack of fundamental knowledge with regards to...

15 Jan at 17:55

Can an event listener be limited to only having one subscriber?

Can an event listener be limited to only having one subscriber? Is it possible to stop multiple subscribers from subscribing to an event? I have created a quick example snippet to give my question som...

16 Jan at 16:57

C# Is there an Exception overview?

C# Is there an Exception overview? I was wondering if there's a list with all Exception types. I know a few Exceptions, but I don't know them all. Sometimes I throw an Exception and then I think, mayb...

18 Jan at 11:11

What Exception Type to throw for strings

What Exception Type to throw for strings If I've got the following, really for any string where you check IsNullOrEmpty and it turns up empty, what kind of exception type should one throw, and ? I alw...

19 Jan at 22:59

How to get a value through a out/ref parameter from a method which throws an exception?

How to get a value through a out/ref parameter from a method which throws an exception? this code outputs "out value". bu

20 Jan at 11:31

Is it abusive to use IDisposable and "using" as a means for getting "scoped behavior" for exception safety?

Is it abusive to use IDisposable and "using" as a means for getting "scoped behavior" for exception safety? Something I often used back in C++ was letting a class `A` handle a state entry and exit con...

20 Jan at 13:13

C# equivalent to Java's Exception.printStackTrace()?

C# equivalent to Java's Exception.printStackTrace()? Is there a C# equivalent method to Java's `Exception.printStackTrace()` or do I have to write something myself, working my way through the InnerExc...

21 Jan at 00:52

C#: An item with the same key has already been added, when compiling expression

C#: An item with the same key has already been added, when compiling expression Ok, here's a tricky one. Hopefully there is an expression guru here who can spot what I am doing wrong here, cause I am ...

Response.Redirect results in "Object moved to here"

Response.Redirect results in "Object moved to here" I'm working on a C# ASP.NET page that normally ends up redirecting to a "file:" URL. This seems to work fine the majority of the time, in the majori...

2 Feb at 14:32

Why does C# allow you to 'throw null'?

Why does C# allow you to 'throw null'? While writing some particularly complex exception handling code, someone asked, don't you need to make sure that your exception object isn't null? And I said, of...

3 Feb at 21:54

In C# how do I define my own Exceptions?

In C# how do I define my own Exceptions? In C# how do I define my own Exceptions?

4 Feb at 14:21

What is the right way to pass on an exception? (C#)

What is the right way to pass on an exception? (C#) I'm wondering what the correct way is to pass on an exception from one method to another. I'm working on a project that is divided into Presentation...

5 Feb at 22:17

C#: Does Visual Studio 2008 have a tool to show which Exceptions could be raised by a piece of code?

C#: Does Visual Studio 2008 have a tool to show which Exceptions could be raised by a piece of code? For example, if I'm opening a file, I know a FileNotFoundException might happen, or if I'm converti...

10 Feb at 23:17

Get a Try statement to loop around until correct value obtained

Get a Try statement to loop around until correct value obtained I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop a...

11 Feb at 12:9

How can I improve this exception retry scenario?

How can I improve this exception retry scenario? I have a web service method I am calling which is 3rd party and outside of my domain. For some reason every now and again the web service fails with a ...

16 Feb at 02:30

Try/catch blocks inside constructors

Try/catch blocks inside constructors Is it a bad programming practice to have try/catch blocks inside constructors? Or does it make no difference as long as our programs handle typeinitializer excepti...

What does the error "the exec task needs a command to execute" mean?

What does the error "the exec task needs a command to execute" mean? When compiling a project in Visual Studio, the error message "the exec task needs a command to execute" appears, with no line numbe...

Is it ok to catch all exception types if you rethrow them wrapped another exception?

Is it ok to catch all exception types if you rethrow them wrapped another exception? I know you're not suppose to write code that caches all exception types like this. Instead you're suppose to do som...

26 Feb at 00:19

Handling fatal exceptions in ViewModel/Model

Handling fatal exceptions in ViewModel/Model I have an application written using the M-V-VM approach. The data access is done in the Model. If a fatal error occurs here (for example, the connection to...

1 Mar at 02:43

C# try-catch-else

C# try-catch-else One thing that has bugged me with exception handling coming from Python to C# is that in C# there doesn't appear to be any way of specifying an else clause. For example, in Python I ...

8 Mar at 10:54

Exception calling when TimeZoneInfo.ConvertTimeToUtc for certain DateTime values

Exception calling when TimeZoneInfo.ConvertTimeToUtc for certain DateTime values When I run the code for this specific value of dt, an exception is thrown when I call the ConvertTimeToUtc Method. My l...

10 Mar at 11:28

What is the difference between an error and an exception in .NET?

What is the difference between an error and an exception in .NET? Could you please explain to me what the difference is between an error and an exception?

12 Mar at 19:57

what happens when two exceptions occur?

what happens when two exceptions occur? what will the program behave when they have two exceptions. And none of them have been caught yet. what type of handler will be called . lets say both the excep...

13 Mar at 20:36

C#: When should I use TryParse?

C#: When should I use TryParse? I understand it doesn't throw an Exception and because of that it might be sightly faster, but also, you're most likely using it to convert input to data you can use, s...

15 Mar at 19:48