exception-handling

Which contract (Design by contract) is better?

Suppose I have a method public Patient(int id) { ---- } that returns Patient object given an id.. I could define contract in 2 ways Method would return null if patient does not exist Method would throw an exception if patient does not exist. In this case I would also define a query method that returns true if the Patient exist i...

Break at throw for excption that is caught

In the VS debugger, un-caught exceptions result in the program breaking at the point the exception is throw (or near enough) and in a state that lets you look at all the stack frames and there local variables up to that point. Is there a way to get this same result (break at throw) but for an exception is caught at a particular point? I...

How to check if array element is null to avoid NullPointerException in Java

I have a partially nfilled array of objects, and when I iterate through them I tried to check to see whether the selected object is null before I do other stuff with it. However, even the act of checking if it is null seem to through a NullPointerException. array.length will include all null elements as well. How do you go about checking...

Is this a bad practice to catch a non-specific exception such as System.Exception? Why?

I am currently doing a code review and the following code made me jump. I see multiple issues with this code. Do you agree with me? If so, how do I explain to my colleague that this is wrong (stubborn type...)? Catch a generic exception (Exception ex) The use of "if (ex is something)" instead of having another catch block We eat SoapEx...

Are there any Videos/Screen casts on how to use exceptions in Delphi

Hi are there any nice videos on how to use exceptions in Delphi. ...

How does "do something OR DIE()" work in PHP?

I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form mysql_connect($host, $user, $pass) or die("could not connect"); How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen it before. ...

How do I stop exceptions trashing my delegate chain?

I have come across what must be a common problem. When I have an event which may be subscribed to by several different classes, an exception thrown by one of these classes will kill the callback chain; as I do not know a priori in what order the callback is carried out, this can result in unpredictable state changes for some classes and ...

How can I guarantee catching a EXCEPTION_STACK_OVERFLOW structured exception in C++ under Visual Studio 2005?

Background I have an application with a Poof-Crash[1]. I'm fairly certain it is due to a blown stack. The application is Multi-Threaded. I am compiling with "Enable C++ Exceptions: Yes With SEH Exceptions (/EHa)". I have written an SE Translator function and called _set_se_translator() with it. I have written functions for and set...

Exception handling of a function in Python

Suppose I have a function definiton: def test(): print 'hi' I get a TypeError whenever I gives an argument. Now, I want to put the def statement in try. How do I do this? ...

How do I stop a program when an exception is raised in Python ?

I need to stop my program when an exception is raised in Python. How do I implement this? ...

Exception that goes away with Clean/Rebuild. How to diagnose/prevent?

Pre-Problem: our office was hit by a worm due to a corporate patching oversight, and the boys in the lab repaved my machine. I needed to re-install all my development tools (Visual Studio 2005, SP1, and the Web Application Project Setup patch) again. The following problem did not occur before this event. I've been working on an ASP.NET ...

Handling errors as exceptions. Best methods?

I'm trying to figure our if there's a good or better method for handling errors in PHP than what I'm doing below. I'd like to throw an exception if there's a problem with the parse_ini_file call. This works, but is there a more elegant way to handle errors? public static function loadConfig($file, $type) { if (!file_exists($file)) { ...

Catching access violation exceptions?

Example int *ptr; *ptr = 1000; can I catch memory access violation exception using standard C++ without using any microsoft specific. ...

JSF generic Exception Handling

If I have an exception in my business layer (e.g. a SQL exception in my JDBC connection bean) how can I propagate it with a custom message to a global error.jsp page? Please help. ...

Custom Exceptions in JavaScript

Can I define custom types for user-defined exceptions in JavaScript? If I can, how would I do it? ...

Exception Logger: Best Practices

I have just started using an exception logger (EurekaLog) in my (Delphi) application. Now my application sends me lots of error messages via e-mail every day. Here's what I found out so far lots of duplicate errors multiple mails from the same PC While this is highly valuable input to improve my application, I am slightly overwhelmed...

Throwing exceptions to control flow - code smell?

Consider this code (Java, specifically): public int doSomething() { doA(); try { doB(); } catch (MyException e) { return ERROR; } doC(); return SUCCESS; } Where doB() is defined as: private void doB() throws MyException Basically, MyException exists only in case doB() meets some condition (which is not cat...

Com Object Exception

I wrote an application that loops through a set of records and prints two things. One is a report from SSRS wich works correctly. The other is a drawing that uses a COM object to print. The COM object randomly fails and causes the program to quit. Is there a way to stop it from killing the entire program when the COM Object fails? ...

is logging an exception on the code of the Exceptions base class a good design approach?

some friends just finished the implementation of an app and they use Custom Exceptions. something that took my attention is that when a custom exception was raised they logged the exception in the code of the exception base class they implemented. so my question will be is this a good design approach?. my thinking is that a logging helpe...

What are some of the strategy to handle unhandled exception in asp.net mvc applications?

I would like to know some of the strategy/practice you deal with to handle unhandled exceptions in ASP.NET MVC. In short I want to avoid the yellow screen whenever any error happens and show a error consistent error message to the visitor. I mean do you write a controller for this which shows the appropriate error page or you go some o...