exception

In Java, what is the best way of continuing to call a function until no exception is thrown?

In my Java code, I have a function called getAngle() which sometimes throws a NoAngleException. Is the following code the best way of writing a function that keeps calling getAngle() until no exception is thrown? public int getAngleBlocking() { while(true) { int angle; try { angle = getAngle(); return ...

Why do many languages treat Exception-objects as first-class citizens?

When we get an objects that is actually are exceptions, we can do with them anything that we can do with ordinar objects in our language. We can pass them as an argument, we can store them in some collection and, what is the worst, we can return them as a result from the methods! So there is a possibility for someone to write smelly cod...

Visual Studio debugging - ignore exception in one place while breaking at it elsewhere?

I have some code which generates a large quantity of ArgumentExceptions on one particular line (which is in a different developer's code, so I can't just change it), which are then caught and handled appropriately. I'm trying to debug ArgumentExceptions which are happening in a different section of code (and are then caught and handled...

Why does MemoryStream.GetBuffer() always throw?

The following code will always throw UnuthorizedAccessException (MemoryStream's internal buffer cannot be accessed.) byte[] buf1 = { 2, 3, 5, 7, 11 }; var ms = new MemoryStream(buf1); byte[] buf2 = ms.GetBuffer(); // exception will be thrown here This is in a plain old console app and I'm running as an admin. I can't imagine a ...

DataGridView Exception thrown during InitializeComponent

This is only occurring on a user's machine, not mine. I cannot recreate this issue. Since this is occurring inside the DataGridView's internal code, I'm not quite sure how to proceed. Any ideas? ************** Exception Text ************** System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the...

How to treat a Linq to Entities query ?

I have this code: public article GetArticleByWebSite(string webSite) { using (var context = new ceopolandEntities()) { return context.article.Where(a => a.WebSite == webSite).First(); } } What's the best way to chceck if article isn't empty before calling First() ? A try catch block or ...

c++ Debugging Exception c0000139

Hi, I am currently trying to get to the bottom of a client crash with one of our applications. I have wrapped the app in an exception handler which creates a mini-dump when the crash occurs. The application crashes with the exception c0000139 (of which there isn't a huge amount of documentation). The callstack looks like this ntdll....

Getting exception while calling WCF service from WCF service

Hi, We are 2 WCF service A) hosted on IIS and B) hosted as Windows service. We are using WSHttp binding When i am calling B from A i am receiving the below error To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding any idea??? ...

How safe is my safe rethrow?

(Late edit: This question will hopefully be obsolete when Java 7 comes, because of the "final rethrow" feature which seems like it will be added.) Quite often, I find myself in situations looking like this: do some initialization try { do some work } catch any exception { undo initialization reth...

InputMissMatchException

I want to read data about MMORPG characters from a .txt file and then filter on experience (minimum experience). But I'm getting this exception, which I know the meaning of but I really don't understand what I'm doing wrong. this my code: I'm not good at java, I'm a beginner actually. Can someone please explain this to me. Probably I'm ...

STL list exception

Hello, I was trying to use an STL list in C++ and I arrived into a strange exception that I'm not able to understand. The list is defined as list<ASTNode*> m_stats; and ASTNode* is a class. When I try to add elements by calling ASTNode *node = new ASTNode(); m_stats.push_back(node); it throws the following exception: Program receive...

iPhone + exception

Hello, Many a times I get the error "EXC_BAD_ACCESS" and my application terminates and I am not able to find because of what I get this error, until I debug my application step by step (which is very time consuming and tedious). Can anyone help me in this. ...

System.ArgumentNullException in System.Threading.Monitor.Enter

I've got a code like this: Some of our clients receiving "System.ArgumentNullException in System.Threading.Monitor.Enter" in the following code block: Public Class CheckStuff Private Shared SLock As New Object Public Sub GetIt() Synclock SLock DoSomething() End Synclock End Sub End Cl...

How should I throw a divide by zero exception in Java without actually dividing by zero?

I have an I2C device that wants two inputs: a denominator and a numerator. Both are written to separate addresses, so no actual calculation (numerator/denominator) is done. The problem with this is that a divide by zero could occur on the I2C device, so a divide by zero error needs to be checked for. Ideally, exactly the same thing would...

Failed to compare two elements in the array

I have a List where T is a class that exposes a "Username" property. Username is of a custom type that encapsulates a string. I implemented the IComparable<T> interface on this custom type that simply returns this.encapsulatedString.CompareTo(other.encapsulatedString) I defined an ICollectionView of the List thus: AllUsers=Collection...

Handling Errors in ExecuteResult ASP.NET MVC

I have a file DownloadResult.cs extended from ActionResult(actually cloned from Phil Haack's one, which u can find at the following location Phil's blog ) Here how do i handle an exception(file not found ) thrown from the method ExecuteResult() in the controller level . for the source code you might want to look at Phil's code , whic...

"Out of Memory" error in nokia 5610 while loading MP3 file.

Hi all, i am developing one j2me application to play wav & mp3 file. problems are: while try to play mp3 file in my phone (nokia 5610d) it is making "Out of memory" error. while try to play Wav file it is giving "Sounds are not allowed" exception. few lines of my code is here. Code to play Wav file InputStream is = getClass()....

ASP.MVC antiforgery token and cryptographic errors

I'm using ELMAH to handle errors in my MVC sites and I've noticed over the past couple of weeks that I'm getting some CryptographicExceptions thrown. The message is: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery t...

When an operation needs to pass more than just the result, do you tuple/throw/or getContextual?

I’m trying to refactor some “sending out an email” code by dividing the steps (validate, attach related content, format, send) into separate classes that can be more easily tested, logged, and updated. As part of this I’ve got to figure out a way for the operations to communicate validation or transient errors (“that item was deleted”)...

Exceptions and IDispatchMessageInspector

I'm using IDispatchMessageInspector to inspect request/response messages in my WCF service and log some data to our logging database. I also have a custom error handler which catches exceptions and transforms them to faults. I'd like to be able to log the exception (if any) in the IDispatchMessageInspector.BeforeSendReply() method but I ...