exception

create std::string from char* in a safe way

I have a char* p, which points to a 0-terminated string. How do I create a C++ string from it in an exception-safe way? Here is an unsafe version: string foo() { char *p = get_string(); string str( p ); free( p ); return str; } An obvious solution would be to try-catch - any easier ways? ...

How do I conditionally suppress application exceptions written to the event log?

I am working on a windows service that polls for a connection to a network enabled devices every 15 seconds. If the service is not able to connect to a device, it throws an exception and tries again in 15 seconds. All of this works great. But, lets say one of the devices is down for a day or more. I am filling up my exception log wit...

Security Error in ASP application

Trying to get an ASP application deployed; it worked for a while but then started coming up with errors whenever the page is accessed: Server Error in '/AppNameHere' Application. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required p...

VC++ linker errors on std::exception::_Raise and std::exception::exception

I am using Visual C++ 2005 Express Edition and get the following linker errors: 19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise@exception@std@@QBEXXZ) referenced in function "protected: static void __cdecl std::v...

Which exception should I raise on bad/illegal argument combinations in Python?

I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so: def import_to_orm(name, save=False, recurse=False): """ :param name: Name of some external entity to import. :param save: Save the ORM object before returning. ...

Is there a way to log or intercept First Chance Exceptions

Short of using a profiler, is there any way inside a running program to detect first chance exceptions? Ideally, I would like to record more detailed state information that is not available once the catch block has taken over the final exception. ...

Is NUnit's ExpectedExceptionAttribute only way to test if something raises an exception?

Hello, I'm completely new at C# and NUnit. In Boost.Test there is a family of BOOST_*_THROW macros. In Python's test module there is TestCase.assertRaises method. As far as I understand it, in C# with NUnit (2.4.8) the only method of doing exception test is to use ExpectedExceptionAttribute. Why should I prefer ExpectedExceptionAttri...

Why are Exceptions iterable?

I have been bitten by something unexpected recently. I wanted to make something like that: try : thing.merge(iterable) # this is an iterable so I add it to the list except TypeError : thing.append(iterable) # this is not iterable, so I add it Well, It was working fine until I passed an object inheriting from Exception which ...

Is there a built in .NET exception that indicates an illegal object state?

What exception should I throw if I encounter an illegal state - for instance, an initialization method that should only be called once being called a second time? I don't really see any built-in exception that makes sense. This seems like something that should be in the framework - am I not poking in the right spot? ...

What style do you use for exception messages?

In writing the code that throws the exception I asked about here, I came to the end of my message, and paused at the punctuation. I realized that nearly every exception message I've ever thrown probably has a ! somewhere. throw new InvalidOperationException("I'm not configured correctly!"); throw new ArgumentNullException("You passed a...

Does WCF suppress first-chance exceptions?

I've got a WCF service that uses a LinqToSql DataContext to fetch some information out of a database. The return type of the operation is IEnumerable<DomainObject>, and I have a helper method that converts from the Table-derived LINQ object to a WCF data contract like so: [OperationContract] public IEnumerable<DomainObjectDTO> RetrieveD...

Finding out what exceptions a method might throw in C#

Is there any way to find out what exceptions might be thrown by any method in .NET code? Ideally I want to see what might be thrown and choose which ones I want to handle. I guess I want the information you'd get from the throws clause in java. The situation is I'm doing a linq query on an xml document from the network and want to know...

How to catch an exception in VB.NET when using jQuery ajax

I'm using jQuery to handle all my ajax needs for an ASP.NET site coded in VB. When I use the built in $.ajax function to POST to a code-behind function and there is an exception, it simply exits the function, and shows an error on the client side. Besides making debugging difficult when coding, the bigger issue is that the Application_E...

How do I approach debugging starting from a Java exception log entry?

I have been trying to parse Java exceptions that appear in a log for some code I'm working with. My question is, do you parse the exception trace from the top down, or the bottom up? It looks something like this: ERROR [main]</b> Nov/04 11:03:19,440 [localhost].[/BookmarksPortlet].[] - Exception sending context... org.springframework.be...

Resharper with large or *very* large files

Hi, I just wanted to know your experience with using resharper. We have a very heavy dbml file as our database has many tables and every time I need to open up that file I start getting lots of exception coming from resharper. Has anyone had that problem before? If yes, what did you do to fix this very ANNOYING problem !?!? Thanks ! An...

Socket Exception: "There are no more endpoints available from the endpoint mapper"

I am using winsock and C++ to set up a server application. The problem I'm having is that the call to listen results in a first chance exception. I guess normally these can be ignored (?) but I've found others having the same issue I am where it causes the application to hang every once in a while. Any help would be greatly appreciate...

NullReferenceException when hosting WPF in a System.AddIn

...

In Java when does a URL connection close?

When does java let go of a connections to a URL? I don't see a close() method on either URL or URLConnection so does it free up the connection as soon as the request finishes? I'm mainly asking to see if I need to do any clean up in an exception handler. try { URL url = new URL("http://foo.bar"); URLConnection conn = url.openConnect...

Is there a cross-platform way of getting information from Python's OSError

On a simple directory creation operation for example, I can make an OSError like this: (Ubuntu Linux) >>> import os >>> os.mkdir('foo') >>> os.mkdir('foo') Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 17] File exists: 'foo' Now I can catch that error like this: >>> import os >>> os.mkdir('...

Catching all unhandled C++ exceptions?

Is there some way to catch exceptions which are otherwise unhandled (including those thrown outside the catch block)? I'm not really concerned about all the normal cleanup stuff done with exceptions, just that I can catch it, write it to log/notify the user and exit the program, since the exceptions in these casese are generaly fatal, u...