exception

Is there a way to determine if an exception is occurring?

In a destructor, is there a way to determine if an exception is currently being processed? ...

Pattern for trying different methods when exception is thrown

Here's a question to expose my lack of experience: I have a method DoSomething() which throws an exception if it doesn't manage to do it cleanly. If it fails, I try the less accurate method DoSomethingApproximately() several times in the hope that it will find a sufficiently good solution; if this also fails I finally call DoSomethingIna...

Catching Exceptions in a Spawned Process

I'm using VS2008 to debug an application that starts a new process. I believe that the spawned process is suffering (and handling) some kind of CLR exception during its start-up, but it is not being caught by turning on CLR Exception Notification in Debug -> Exceptions. Any suggestions on how I can see where the exception is generated? I...

Compile-time error for NotSupportedException in subclass function

If I have a subclass that has yet to implement a function provided by the base class, I can override that function and have it throw a NotSupportedException. Is there a way to generate a compile-time error for this to avoid only hitting this at runtime? Update: I can't make the base class abstract. ...

When should I use Debug.Assert()?

I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at all until recently. Our production code contains no asserts whatsoever and my question is this... Should I begin using Asserts in our pr...

Generic Exception Handling in Python the "Right Way"

Sometimes I find myself in the situation where I want to execute several sequential commands like such: try: foo(a, b) except Exception, e: baz(e) try: bar(c, d) except Exception, e: baz(e) ... This same pattern occurs when exceptions simply need to be ignored. This feels redundant and the excessive syntax causes it t...

How do you test that a Python function throws an exception?

How does one write a test that fails only if a function doesn't throw an expected exception? ...

throwing exceptions out of a destructor

Most people say never throw an exception out of a destructor - doing so results in undefined behavior. Stroustrup makes the point that "the vector destructor explicitly invokes the destructor for every element. This implies that if an element destructor throws, the vector destruction fails... There is really no good way to protect agains...

Can you Catch an Exception after the main application unit has ended?

In one of our application im getting an exception that i can not seem to find or trap. ... Application.CreateForm(TFrmMain, FrmMain); outputdebugstring(pansichar('Application Run')); //this is printed Application.Run; outputdebugstring(pansichar('Application Run After')); //this is printed end. <--- The Exception seems to b...

Do I have to cause an ValueError in Python

I have this code: chars = #some list try: indx = chars.index(chars) except ValueError: #doSomething else: #doSomethingElse I want to be able to do this because I don't like knowfully causing Exceptions: chars = #some list indx = chars.index(chars) if indx == -1: #doSomething else: #doSomethingElse Is there a wa...

How do you prefer to organize exception definitions?

I almost feel embarrassed to ask, but I always struggle with how to organize exception definitions. The three ways I've done this before are: Use the file-per-class rule. I'm not crazy about this because it either clutters up my directory structure and namespaces. I could organize them into subdirectories and segment namespaces for ...

What are possible reasons for java.io.IOException: "The filename, directory name, or volume label syntax is incorrect"

I am trying to copy a file using the following code: File targetFile = new File(targetPath + File.separator + filename); ... targetFile.createNewFile(); fileInputStream = new FileInputStream(fileToCopy); fileOutputStream = new FileOutputStream(targetFile); byte[] buffer = new byte[64*1024]; int i = 0; while((i = fileInputStream.read(buf...

Method 'XYZ' cannot be reflected

We have consumed a third party web service and are trying to invoke it from an ASP.NET web application. However when I instantiate the web service the following System.InvalidOperationException exception is thrown: Method 'ABC.XYZ' can not be reflected. System.InvalidOperationException: Method 'ABC.XYZ' can not be reflected. -...

C# Exception Handling continue on error

I have a basic C# console application that reads a text file (CSV format) line by line and puts the data into a HashTable. The first CSV item in the line is the key (id num) and the rest of the line is the value. However I've discovered that my import file has a few duplicate keys that it shouldn't have. When I try to import the file the...

c++ exception : throwing std::string

Hello, I would like to throw an exception when my C++ methods encounter something weird and can't recover. Is it OK to throw a std::string pointer? Here's what I was looking forward to doing: void Foo::Bar(){ if(!QueryPerformanceTimer(&m_baz)){ throw new std::String("it's the end of the world!"); } } void Foo:Caller(){ try{...

DRY way of re-raising same set of exceptions in multiple places

short: Is there a way in Ruby to DRY-ify this: def entry_point_one begin do_something rescue MySyntaxErrorOne, MySyntaxErrorTwo, MySyntaxErrorEtc => syn_err raise syn_err.exception(syn_err.message) end end def entry_point_two begin do_something_else rescue MySyntaxErrorOne, MySyntaxErrorTwo, MySyntaxErrorEtc => s...

Catching exceptions within .aspx and .ascx pages

The questions says everything, take this example code: <ul id="css-id"> <li> <something:CustomControl ID="SomeThingElse" runat="server" /> <something:OtherCustomControl runat="server" /> </li> </ul> Now if an error gets thrown somewhere inside these controlls (that are located in a master page) they will take down the...

ASP.NET: Unable to validate data.

What is the cause of this exception in ASP.NET? Obviously it is a viewstate exception, but I can't reproduce the error on the page that is throwing the exception (a simple two TextBox form with a button and navigation links). FWIW, I'm not running a web farm. Exception Error Message: Unable to validate data. Error Source: S...

Exception thrown inside catch block - will it be caught again?

This may seem like a programming 101 question and I had thought I knew the answer but now find myself needing to double check. In this piece of code below, will the exception thrown in the first catch block then be caught by the general Exception catch block below? try { // Do something } catch(IOException e) { throw new Application...

What you think about throwing an exception for not found in C++?

I know most people think that as a bad practice but when you are trying to make your class public interface only work with references, keeping pointers inside and only when necessary, I think there is no way to return something telling that the value you are looking doesn't exist in the container. class list { public: value...