exception

PHP - Converting all Errors to Exceptions - Good or Bad?

I was wondering if it's considered a bad practice to globally convert all PHP Errors to Exceptions. Something like the following would be used: function exception_error_handler($errno, $errstr, $errfile, $errline ) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); return false; } I suppose the assumption is ...

Should I use exceptions in C# to enforce base class compatibility?

On one hand, I'm told that exceptions in C# are 'expensive', but on the other, I'm stuck on how to implement this. My problem is this: I'm making a Stream derivitive, that wraps a NetworkStream. Now, the problem I'm facing is this: Read(byte[] buffer, int offset, int count). From the Stream docs for the function: Returns: ... o...

Several catch blocks or one with dynamic_cast?

We have a hierarchy of exception classes - there's a GenericException class and a number of classes that derive from it. GenericException is polymorphic - it has a virtual destructor. One of derived classes is FileException thrown to indicate errors when manipulating with filesystem objects. FileException has GetErrorCode() method that ...

ThreadAbortException in SQL Server CLR stored procedure

This is kinda weird... I remember that I once had this, but can't remember the cause or solution... In a CLR stored procedure (SQL Server 2005) of mine I get a ThreadAbortException. All the details I have are the following: System.TypeInitializationException: The type initializer for 'Microsoft.SqlServer.Server.SmiContextFactory' th...

How to test a program processing large amounts of data stored in an unpredictable format

What I have to do I'm trying to manipulate some rather large amounts of data stored in Excel files (one of the workbooks has as much as 150 spreadsheets). The result of these manipulations may yield approximately 800.000 rows in a database table. The problem Data stored in the spreadsheets has unpredictable format. The company that ge...

What happens if a throw; statement is executed outside of catch block?

In C++ throw; when executed inside a catch block rethrows the currently caught exception outside the block. In this answer an idea of exception dispatcher is brought up as a solution to reducing code duplication when using complex exception handling often: try { CodeThatMightThrow(); } catch(...) { ExceptionHandler(); } void E...

Correct way of handling exceptions in Python?

Hello there everyone, I have searched for other posts, as I felt this is a rather common problem, but all other Python exception questions I have found didn't reflect my problem. I will try to be as specific here as I can, so I will give a direct example. And pleeeeease do not post any workarounds for this specific problem. I am not spe...

C#: Do you raise or throw an exception?

I know that this probably doesn't really matter, but I would like to know what is correct. If a piece of code contains some version of throw new SomeKindOfException(). Do we say that this piece of code can potentially raise an exception? Or throw an exception? The keyword is throw, so I am kind of leaning towards that, but to raise an ...

How can I determine which exceptions can be thrown by a given method?

My question is really the same as this one "Finding out what exceptions a method might throw in C#". However, I would really like to know if anyone knows of a way to determine the stack of all the exceptions that may be thrown by a given method. I am hoping for a tool or utility that I can analyze code at compile time or through reflecti...

Why do my WCF service returning a FaultException, time out after 10 calls?

I have a WCF service that sometimes has to return a Fault. For some reason, the calls to my service begins to time out with the following error: "The request channel timed out while waiting for a reply after 00:00:59.8906201. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The ti...

In Java, is using throws Exception instead of throwing mulitple specific exceptions good practice?

While looking through the Spring MVC framework I noticed that, unless I misunderstand, its developers favor throws Exception instead of throwing multiple exceptions. I realize that at the core of this question is the checked versus unchecked exceptions debate, avoiding that religious war, is it a good practice to use throws generic exce...

Rails Exception notifier is not working

I installed the exception notification plugin from http://github.com/rails/exception_notification/tree/master I can confirm that my ActionMailer is working as I received emails from other process. Although, I can see the notifier sending the email in the log (Sent mail to [email protected] ) and the email address was written correct, I d...

Exception handling pattern for this type of situation?

I have 2 APIs from 2 different companies that allow me to communicate with their servers in order to process transactions. I am tasked with creating a generic interface to these APIs. I came up with something like this: IServiceProvider <- ServiceProvider <- CompanyAServiceProvider IServiceProvider <- ServiceProvider <- CompanyBServiceP...

Do I have to break after throwing exception?

I'm writing a custom class in C# and I'm throwing a couple exceptions if people give the wrong inputs in some of the methods. If the exception is thrown, will any of the code in the method after the throw still be executed? Do I have to put a break after the throw, or does a throw always quit the method? ...

How do I determine the HResult for a System.IO.IOException?

The System.Exception.HResult property is protected. How can I peek inside an exception and get the HResult without resorting to reflection or other ugly hacks? Here's the situation: I want to write a backup tool, which opens and reads files on a system. I open the file with FileAccess.Read and FileShare.ReadWrite, according to this...

How does the C++ runtime determine the type of a thrown exception?

If I do the following, how does the runtime determine the type of the thrown exception? Does it use RTTI for that? try { dostuff(); // throws something } catch(int e) { // .. } catch (const char * e) { // .. } catch (const myexceptiontype * e) { // .. } catch (myexceptiontype e) // is this the same as the previous handler? { /...

ExceptionList Class - VB

Hi, I need to return an exception that contains a list of exceptions. This is easy enough to do, but I'd like to know if there is a built-in Exception Class that does this as I'd hate to "roll my own" instead of following built-in, documented classes. Thanks, Larry ...

Solving UnauthorizedAccessException issue for listing files

Listing all files in a drive other than my system drive throws an UnauthorizedAccessException. How can I solve this problem? Is there a way to grant my application the access it needs? My code: Directory.GetFiles("S:\\", ...) ...

Windows: avoid pushing full x86 context on stack

I have implemented a language under MS Windows that uses cactus stacks to implement parallel programs. The stack chunks are allocated on a per-function basis and are just the right size to handle local variables, expression temp pushes/pops, and calls to libraries (including stack space for the library routines to work in). Such stack ...

Usage of Exceptions

In a Spring application, my point of view is that each domain model which in fact is a POJO, should encapsulate all the validation logic in itself. Now whenever there is an update or insertion, they should throw proper exceptions that are modeled after the business process like CustomerNotFound AlreadySold, CannotAllowReturnOfExpiredItem...