exception

Casting Exceptions in C#

Why do I get an InvalidCastException when trying to do this? throw (ArgumentNullException)(new Exception("errormessage", null)); This is a simplified version of the following function. public static void Require<T>(bool assertion, string message, Exception innerException) where T: Exception { if (!assertion) { ...

WPF Data Validation from a property setter function

Hi There, I have a class that is bound to GUI elements as follows: <TextBox Style="{StaticResource ValidatedTextBox}" Text="{Binding MaxDistance, ValidatesOnExceptions=True}" > <TextBox.Style> <Style TargetType="TextBox" > <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <Setter Pr...

.Net Throwing exceptions from ToString?

Just curious if anyone has any opinions on throwing an exception in my overridden ToString implementation. My instincts tell me this might be bad practice, but I don't seem to be able to find anything supporting if this is bad or not. Any thoughts? Code: http://pastebin.com/mLEkBAAz Thanks. ...

A potentially dangerous Request.Form value was detected from the client

Hi! I'm using ASP.NET MVC2 and what I did didn'T help me to get rid of this exception. I put [ValidateInput(false)] before the conntroller, changed web.config but again getting this exception. What I should do? EDIT: I'm posting HTML values. ...

TOO MANY THREADS ERROR EXCEPTION

Hi, i am facing a problem while making an application of Blackberry that i have upto 7 threds call, of which each downloads an audio from the Server and it works fine but when i start my application twice then an uncaught exception has been occurred that "TOO MANY THREADS ERROR EXCEPTION", So, let me know that how i can solve this proble...

Handle exception or throw exception in Java

Like such Java code snippet: public void func() throws XXXException { // throw exception to outer body ------ (2) try { ...... } catch(XXXException ex) { // handle exception ------ (1) } } In this condition, how you decide to choose (1) or (2)? Is there any principles in Java exception handling? ...

Sending an exception from thread to main thread?

Hi I want to pass an exception from current thread(that thread isn't main thread)to main thread. Why?cuz I check my hard lock in another thread(that thread use timer for checking), and when HardLock is not accessible or invalid, I create an exception which is define by myself and then throw that exception. So that exception don't work we...

How can I get powershell exception descriptions into a string?

I want to have access to the same message that Powershell prints when you send an error record to the output stream Example: This is the exception message At C:\Documents and Settings\BillBillington\Desktop\psTest\exThrower.ps1:1 char:6 + throw <<<< (New-Object ArgumentException("This is the exception")); + Category...

Handling a class that doesn't throw exception in c#

I've got some UI code that looks like this: try { SomeClass classInstance = new SomeClass(someId); } catch (Exception exception) { // Content wasn't created, show a message, stop processing return; } It seems the try catch was added because the constructor for SomeClass would bomb out if the someId it receives isn't valid,...

Why does this Ruby statement throw an exception? (Arrays/Bools)

I'm not a Ruby guy, I just play one on television. I have to modify someone's old Cron job to pull down some JSON and convert it into objects. Here's the code raw_json = Net::HTTP.get(URI.parse("url removed to protect the innocent")) tags = ActiveSupport::JSON.decode(raw_json) puts tags.count tags.count will accurately trace as 5, ...

Paranoia, excessive logging and exception handling on simple scripts dealing with files. Is this normal?

I find myself using python for a lot of file management scripts as the one below. While looking for examples on the net I am surprised about how little logging and exception handling is featured on the examples. Every time I write a new script my intention is not to end up as the one below but if it deals with files then no matter what m...

How to return an error code with Halt(n) from an Exception block with D2007?

Update: It seems to be specific to D2007. It works in D2010 like it worked in older version. I would like to return an exit code depending on the type of Exception caught in the Eception Handler block like: program test; {$APPTYPE CONSOLE} uses SysUtils; var Exitcode: Integer; begin Writeln('Enter error code:'); Readln(Exi...

Panic recover in Go v.s. try catch in other languages

I've just read this post about Panic/Recover in Go and I'm not clear on how this differs from try/catch in other mainstream languages. ...

How do I bubble up and Exception to my UI. ASP.net

Hi All, I have an aspx page that, on a button click, creates an instance of a serviceRefernece object. In the code behind for my page I have the call wrapped in a try/catch. try { var client = GetClient(); var request = new ActiveVerificationRequestDC(); var response = client.GetActiveVeri...

Getting OutofMemoryException at runtime with the message "Insufficient memory to continue the execution of the program".

Hi, I am getting OutofMemoryException at runtime with the message "Insufficient memory to continue the execution of the program.". I am loading the images at the start of program. Each image is 50+ MB. If the images size goes to 277 MB plus, then I get this exception. I am loading the images at once because I have to display their thumb...

throw new RuntimeException("Compiled Code")?

I've just looked into the code of javax.ws.rs.core.MediaType and wondered about throw new RuntimeException("Compiled Code"), since I've never seen that before. I think is a form of "not implemented", but don't know. package javax.ws.rs.core; import java.util.Map; import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate; public class Med...

What is 'exceptional'?

I'm looking for a definition of 'exceptional' in terms of unit testing or OOP principles. Several times on SO when talking about exception throwing, I've seen comments like, "Well, I wouldn't consider getting Foo from Bar to be exceptional." (Is there a trollface emoticon?) I did some googling and an answer wasn't immediately forthcomi...

Conventions for Assembling Multiple Error Message Exceptions

I have a list of validations to run against an object, each a separate method which takes the object as a parameter. As each validation fails, I will create an appropriate error message. At the end of the validation process, I will throw a custom exception containing a list of all the error messages. My question is, I've seen this don...

PHP Converting errors to exceptions design flaw

I came across some code recently that used a custom error handler to turn any PHP errors into an generalized application exception. A custom exception handler was also defined that would log the exception if it was within a particular error code range. Example: class AppException extends Exception { } function error_handler($errno, $e...

Best Practice for Try Catch Error Handling

I'm trying to avoid returning an incorrect value when in the catch but I'm having trouble finding a better solution than this: private SecurityLevel ApiGetSecurityLevel() { try { return _BioidInstance.GetSecurityLevel(); } catch { return SecurityLevel.High; ...