exception

Python Exception handling

C has perror and errno, which print and store the last error encountered. This is convenient when doing file io as I do not have to fstat() every file that fails as an argument to fopen() to present the user with a reason why the call failed. I was wondering what is the proper way to grab errno when gracefully handling the IOError excep...

Do you end your exception messages with a period?

I've seen both exception messages with and without a period. And I can think of some reasons of why both could be good. No dot would give you the freedom to add the period or leave it out if you wanted to. Could be useful if the message was going in some sort of a titlebar or something. WIth a dot you would always know that you had a "...

Why does this "finally" execute?

If you run the code below it actually executes the finally after every call to the goto: int i = 0; Found: i++; try { throw new Exception(); } catch (Exception) { goto Found; } finally { Console.Write("{0}\t", i); } Why? ...

Exceptions: Compare Message Property to Know what it Means?

Sometimes in an application, one might compare the Message text of an exception. For instance, if ex.Message.Contains("String or binary data would be truncated") then a MessageBox will be displayed for the user. This works when testing on an English-language Windows system. However, when the program is run on a system with a differen...

Why is DebugHook not set to 1 in my Delphi add-in DLL?

When I'm running my COM Office add-in from within the Delphi 5 IDE (using any of the office applications as the host), breakpoints work fine (when using remote debugging symbols and a properly set output folder), but none of the non-delphi exceptions (like access violations) in my code triggers the IDE to break at that point. In stead, t...

"EXC_BAD_ACCESS" error when cell begins scrolling back in view?

I've got some (I think) pretty basic code for creating cell content from a data source, and everything works fine when the display loads. However, when I start scrolling around to view other text (up or down) the code fails with 'GDB: Program received signal: "EXEC_BAD_ACCESS"'. Here's the code that fills out the display for the various ...

Named Iterator & Exceptions

Hi, I am writing a method which needs to check some parameters and if they are validated return an IEnumerable. E.g. public static IEnumerable<double> GetEnum(int param) { if (!IsValidParameter(param)) { throw new Exception(); } while(true) { yield return 5.0; } } However, I believe because of...

cleaning up when using exceptions and files in python

Hello all, I'm learning python for a couple of days now and am struggling with its 'spirit'. I'm comming from the C/C++/Java/Perl school and I understand that python is not C (at all) that's why I'm trying to understand the spirit to get the most out of it (and so far it's hard)... My question is especially focused on exception handlin...

Exception handeling performance

Hi While using try-catch blocks, even if any exceptions are not thrown, does it consider performance of the code? I wanted to code my own Exception handler which extends from standard exception class, was wondering if this situation downs the performance of the page on several calls. Regards ...

ASP.NET MVC, HandleError Attribute, and Tracing: Bug?

I seem to be encountering some funky behaviour when tracing is enabled in an ASP.NET MVC application: Whenever tracing is enabled, the HandleError attribute fails. I've reproduced this on the vanilla ASP.NET MVC app, and was wondering whether anyone has experienced anything similar. Steps to Reproduce Step 1 Create a new ASP.NET MVC...

Is it better to use an exception or a return code in Python?

You may know this recommendation from Microsoft about the use of exceptions in .NET: Performance Considerations ... Throw exceptions only for extraordinary conditions, ... In addition, do not throw an exception when a return code is sufficient... (See the whole text at http://msdn.microsoft.com/en-us/library/sys...

how to serialise exception object as xml string c#

I want something like try { //code here } catch (Exception ex) { stringXML = Exception.toXML(); } so that the value of stringXML would be <exception><message></message><innerException></innerException></exception> For example... How is this possible? ...

UnauthorizedAccessException trying to delete a file in a folder where I can delete others files with the same code

I'm getting a Unauthorized Access Exception in a file wich I can delelete manually. in a folder where I'm able to delete by code other files and the file isn't marked as read only besides, I'm using windows XP in an standalone PC and I have not assigned any permissions to the folder or the file. any other process is using the file ...

Why do exceptions propogate out of an event handler?

Consider the following program. How is the behaviour that it displays (namely that exceptions will propagate out of an event handler) a "good thing"? As far as I can tell, it could only ever be bad; unexpected exceptions popping up from functions that they shouldn't. In my particular case, it was killing threads. So, is this behaviour ac...

Proxy exception in service but not app

I make a web request from both an application and a service. From the application (user context), the request works fine. However, the service (LocalSystem context) catches this: System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required. Why can the application get out but the service can't? Do ...

How to save contacts in an address book and list them?

I am working on making an address book in C# 2008. I need to be able to save the contacts and then later display them when the user asked for it. I also need to handle an exception when someone enters an unknown color when writing the person's favorite color. This is my code so far: using System; using System.Collections.Generic; using ...

DLL runtime error crashes my c# app - how to avoid it?

Hi, Within my windows app, i'm using a c++ DLL wrapped with a .NET DLLs (specifically - the quickfix engine). While running, once every day (not at any specific time), in one of the a constructor of one of the built-in classes throws a runtime error. Even though the error is caught and reported (to a log file, and the database), I still...

jQuery AJAX request fails on PHP exception

Hi, I'm using the Kohana PHP Framework for an application. Now I'm running into a problem, when jQuery does an AJAX request to a certain file, it does work, but when this file throws an PHP exception, jQuery fails and doesn't show the output of the file. A little example, this is the piece of Javascript: $.post($('#' + e.currentTarget...

Playing audio in j2me fails

I'm having difficulty playing any audio in my j2me application. I've tried to play a simple tone, only to receive an exception: "Device Busy, cannot play the tone". I've tried to play an mp3 file that is embedded in my .jar and ended up getting an exception stating that the media contains Unsupported Data. Here's the code that I u...

Should TryFoo ever throw an exception?

A common pattern in the .NET Framework is the TryXXX pattern (I don't know if that's what they really call it), in which the called method attempts to do something, returning True if it was successful, or False if the operation failed. A good example is the generic Dictionary.TryGetValue method. Documentation for these methods say that...