exception-handling

Which exception to throw when not finding a WebForms control which "should" be there

Hi! We have a WebForms Control which requires that the ID of another Control implementing ITextControl is provided. What exception should we throw if there is no control with that ID or a control is found but it's not implementing the interface? var text = Page.FindControl(TextProviderId) as ITextControl; if (text == null) { throw...

WCF Exception Handling

If an exception occurs in my WCF service, what is the best way to communicate that error to the client? Should I log it on the service and rethrow a soap exception? Or should I log it and return a user friendly message? ...

What is the purpose of throwing specific exception subclasses?

Why is it preferable to throw this Exception Throw New DivideByZeroException("You can't divide by zero") over this general one: Throw New Exception("You can't divide by zero") What advantage is gained in this particular example? The message already tell it all. Do standard subclasses that inherit from the base Exception class ever ...

Can you add a handler for WPF event exceptions?

I have a single-threaded IronPython WPF application and if an event handler (FrameworkElement.SizeChanged for example) throws, the exception is just eaten and execution continues without any kind of notification. Because of this I spent a lot of time today solving an "impossible" bug. Does the same thing happen when using WPF from C#? ...

pyodbc and mySQL

I am unable to connect to mySQl db using pyodbc. Here is a snippet of my script: import pyodbc import csv cnxn = pyodbc.connect("DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=mydb; UID=root; PASSWORD=thatwouldbetelling;") crsr = cnxn.cursor() with open('C:\\skunkworks\\archive\\data\\myfile.csv','r') as myfile: rows...

exception handling and (throw ex)

what is the best way to handle an exception? and why should i never write: catch (Exception ex) { throw ex; } ...

Best way to check function parameters: Check for null or try/catch

Hello everyone, when implementing/using methods that return or work with instances of objects, what is the most elegant approach to check the function parameters ? Method to call: someType GetSomething(object x) { if (x == null) { return; } // // Code... // } or better: someType GetSomething(object x) {...

Symfony 1.4 - forward404 pass message to error404 template in production mode

In my app I want to use $this->forward404("Data not found"); to output individual error messages when necessary. In the dev mode it works fine. When I run my app in production mode - where debug is set to false in getApplicationConfiguration() - I don't get the messages anymore. in settings.yml I set a custom 404 action. all: .actions...

Memory Management and Exception Handling

Hello, I have a simple class that handles the connection being made between a client and server. To let more than one user communicate with the server at one time each new Client connection is made on a separate thread. In this class I create two streams that act as the inbound and outbound streams for the client. I create the fields ...

trigger_error vs. throwing exceptions

A similar question was asked here, but as the answers didn't answer my question, I'm asking: I've almost never used trigger_error, always thrown exceptions instead, since in my mind errors are legacy. But I've changed my mind, I think they can co-exist. There are cases when triggering errors make more sense. I'm updating this library, ...

Getting the error code from an IOException

Getting the (hex) error code from an IOException, or regular Exception! Is this possible? i know it HAS a error code, (HResult) but the get accessor is private. I would do some sort of ComException thing, but im not sure about the pros/cons of doing this, and if its even possible/the same. ...

Add extra information to exceptions

Assume I have method that reads customers from a csv file. When reading the file an exception occurs (e.g. IOException or FormatException). In most cases the method can't do anything about the errors but it can add extra information like file name, line number etc. The method's class got an IProgressAndErrorReporter dependency that is ...

Is it a good practice to catch all exceptions and re-throw them as a particular type of exception in terms of classification?

Hi! Is it a good practice to catch all exceptions and re-throw them as a specific type -basically to classify all the exceptions thrown from a particular part (or service) of an application? Something like: // This class is used to label all the exceptions occured on // Race Cars Service calls as RaceCarsServiceException public clas...

else clause in try statement... what is it good for

Possible Duplicate: Python try-else Comming from a Java background, I don't quite get what the else clause is good for. According to the docs It is useful for code that must be executed if the try clause does not raise an exception. But why not put the code after the try block? It seems im missing something importan...

Python with statement - is there a need for old-style file handling any more?

With having the with statement, is there ever a need to open a file/check for exceptions/do manual closing of resources, like in try: f = open('myfile.txt') for line in f: print line except IOError: print 'Could not open/read file' finally: f.close() ...

How do I print Python 2.5 Exception arguments?

Does python 2.5 allow you to pass exception arguments? try: raise Exception("argument here") except Exception: print Exception.args I've had no luck with the above code - I know this is how you do it in Python 2.7 - is this not in Python 2.5? ...

What is the best way to handle exceptions in perl?

I've noticed that Exception.pm and Error.pm don't seem to be extensively used in the perl community. Is that due to the large footprint of eval for exception handling? Also perl programs appear to have a much more lenient policy regarding exception handling in general. Is there a compelling reason for this? In any event what would be...

exception handling for optparse of python

HI, guys. I am using cmd and optparse to develop a CLI.py for a collection of already-functional classes (CDContainer, CD, etc.). The following are some parts of the code. I have a problem here. when there are exceptions(wrong input type or missing values), the optparse will exit the whole program instead of the specific command method...

WCF - Catching faults on the server and returning custom types instead

We are trying to figure out a way to modify WCF service behavior to catch all exceptions and instead of returning faults to the client, it will populate a custom return object with exception data and return that. So far, we haven't had much luck. I found this example: Catching custom faults However, it doesn't return custom types as we ...

PHP: managing url $_GET tinkering

hi, Here's a situation, i have a list of support tickets that when you click the title of the ticket takes you to a page that displays the ticket in more detail. If uses URL GET variables to query the database. I've taken SQL injection into account but what if someone modifies the url to an id that doesn't exist? whats the best way to d...