exception

Using Exception.Data

How have you used the Exception.Data property in C# projects that you've worked on? I'd like answers that suggest a pattern, rather than those that are very specific to your app. Thanks! ...

Will the below code cause memory leak in c++

class base{ int a; int *pint; someclass objsomeclass; someclass* psomeclass; public: base(){ objsomeclass = someclass(); psomeclass = new someclass(); pint = new int(); throw "constructor failed"; a = 43; } } main(){ base temp(); } in the above code constructor...

Javascript exception stack trace

In Firefox I can get the stack trace of an exception by using exception.stack. Is there a way to get that in other browsers, too? Edit: I actually want to save the stack trace automatically (if possible) and not debug it at the time (i.e. I know how to get the stack trace in a debugger). ...

Using events rather than exceptions to implement error handling

I'm working on some code that uses a pattern in its business and data tiers that uses events to signal errors e.g. resource = AllocateLotsOfMemory(); if (SomeCondition()) { OnOddError(new OddErrorEventArgs(resource.StatusProperty)); resource.FreeLotsOfMemory(); return; } This looked superficially rather odd, espec...

C# "Using" Syntax

Does the using catch the exception or throw it? i.e. using (StreamReader rdr = File.OpenText("file.txt")) { //do stuff } If the streamreader throws an exception is it caught by using or thrown so the calling function can handle it? ...

preconditions and exceptions

Suppose you have a method with some pre and post-conditions. Is it ok to create an exception class for each pre-condition that is not accomplished? For example: Not accomplishing pre1 means throwing a notPre1Exception instance. ...

Exception Thrown Causes RunTime Error.

We have developed a website that uses MVC, C#, and jQuery. In one of my controller classes we are validating inputs from the user and if it fails we throw an exception that the Ajax error parameter(aka option) handles. (We use Block UI to display the error message. BlockUI is a jQuery plugIn that blocks the screen and displays a message...

Can you catch a native exception in C# code?

In C# code can you catch a native exception thrown from deep in some unmanaged library? If so do you need to do anything differently to catch it or does a standard try...catch get it? ...

What exceptions might a Python function raise?

Is there any way in Python to determine what exceptions a (built-in) function might raise? For example, the documentation (http://docs.python.org/lib/built-in-funcs.html) for the built-in int(s) says nothing about the fact that it might raise a ValueError if s is not a validly formatted int. This is a duplicate of http://stackoverflow...

Which is correct? catch (_com_error e) or catch (_com_error& e)?

Which one should I use? catch (_com_error e) or catch (_com_error& e) ...

Errors with Python's mechanize module

Hello, I'm using the mechanize module to execute some web queries from Python. I want my program to be error-resilient and handle all kinds of errors (wrong URLs, 403/404 responsese) gracefully. However, I can't find in mechanize's documentation the errors / exceptions it throws for various errors. I just call it with: self.browser...

DataReader within try block causing potential null reference error

There is probably is simple fix for this but I currently have code similar to dim dr as dbDataReader try dr = connection.getDataReader(sql_str) Catch ex as sqlClientException log.error(ex) finally if not IsNothing(dr) then dr.close end if end try However Visual Studio still warns me that the if not IsNothing(d...

Is there a way to define an action for unhandled exceptions in a WinForms .NET 3.5 app?

Note, I realize that this has been addressed here. That post discusses exception handling in .NET 1.1 while implying that there is a better solution for >.NET 2.0 so this question is specifically about the more recent .NET versions. I have a windows forms application which is expected to frequently and unexpectedly lose connectivity to...

Handling exceptions raised during method called via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:

What happens to exceptions raised while in myMethod: if it is invoked via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:? In particular, can I catch them in the scope of the call to performSelectorOnMainThread like this... @try { [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:Y...

Closing a Java FileInputStream.

Alright, I have been doing the following (variable names have been changed): FileInputStream fis = null; try { fis = new FileInputStream(file); ... process ... if (fis != null) fis.close(); } catch (IOException e) { ... blah blah blah ... } Recently, I started using FindBugs, which suggests that I am not p...

In a .net Exception how to get a stacktrace with argument values

I am trying to add an unhandled exception handler in .net (c#) that should be as helpfull for the 'user' as possible. The end users are mostly programers so they just need a hint of what object are they manipulating wrong. I'm developing a windows similar to the windows XP error report when an application crashes but that gives as much ...

RAII vs. exceptions

The more we use RAII in C++, the more we find ourselves with destructors that do non-trivial deallocation. Now, deallocation (finalization, however you want to call it) can fail, in which case exceptions are really the only way to let anybody upstairs know of our deallocation problem. But then again, throwing-destructors are a bad idea b...

Catching exceptions from a constructor's initializer list

Here's a curious one. I have a class A. It has an item of class B, which I want to initialize in the constructor of A using an initializer list, like so: class A { public: A(const B& b): mB(b) { }; private: B mB; }; Is there a way to catch exceptions that might be thrown by mB's copy-constructor while still using the ...

Does C++ support 'finally' blocks? (And what's this 'RAII' I keep hearing about?)

Does C++ support 'finally' blocks? What is the RAII idiom? What is the difference between C++'s RAII idiom and C#'s 'using' statement? ...

How slow are .NET exceptions?

I don't want a discussion about when to and not to throw exceptions. I wish to resolve a simple issue. 99% of the time the argument for not throwing exceptions revolves around them being slow while the other side claims (with benchmark test) that the speed is not the issue. I've read numerous blogs, articles, and posts pertaining one sid...