throw

Catching Exceptions Syntax Error in PHP

I'm trying to use exceptions in PHP as a way of avoiding multiple if-then-else blocks. However, when I try to catch the exception, I get the error Parse error: syntax error, unexpected T_CATCH in /directory/functions.php on line 66. Am I doing something wrong with my throwing and catching? function doThis($sSchool, $sDivision, $sClass, ...

When should I use a ThrowHelper method instead of throwing directly?

When is it appropriate to use a ThrowHelper method instead of throwing directly? void MyMethod() { ... //throw new ArgumentNullException("paramName"); ThrowArgumentNullException("paramName"); ... } void ThrowArgumentNullException(string paramName) { throw new ArgumentNullException(paramName); } I've read that calli...

catch exception by pointer in C++

Hi, I found that there are three ways to catch an exception, what are the differences? 1) catch by value; 2) catch by reference; 3) catch by pointer; I only know that catch by value will invoke two copies of the object, catch by reference will invoke one. So how about catch by pointer? When to use catch by pointer? In addition to th...

rake: Best way of handling an undefined parameter?

I've got a rake task on a rails app that needs one parameter, called USER_ID. I think I'd like to throw an exception that halts the execution. This is what my task looks like: desc "My rake task" task :my_task => :envionment do user_id = ENV["USER_ID"] or # THROW SOMETHING HERE # ... do stuff with user_id end What code goes on...

Lifetime of a thrown object caught by reference

The C++ Standard, paragraph 15.1.4 sais: The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in 3.7.3.1. The temporary persists as long as there is a handler being executed for that exception. I'm wondering why this code crashes (I know that it's not best practice): c...

Performance cost of coding "exception driven development" in Java?

Are there are any performance cost by creating, throwing and catching exceptions in Java? I am planing to add 'exception driven development' into a larger project. I would like to design my own exceptions and include them into my methods, forcing developers to catch and do appropriate work. For example, if you have a method to get a us...

Do I specify exception types in just the function header or declarations as well? (C++)

SVector.H: void pop_back() throw (underflow_error); In my SVector.cpp file, should I also include the throw (underflow_error) part as well? void pop_back() throw (underflow_error) { // implementation } OR void pop_back() { // implementation } Thanks. ...

Are destructors of automatic objects invoked when terminate is called?

I'm pondering a question on Brainbench. I actually realised that I could answer my question easily by compiling the code, but it's an interesting question nonetheless, so I'll ask the question anyway and answer it myself shortly. Take a look at this snippet: The question considers what happens when we throw from a destructor (which c...

Does throw inside a catch ellipsis (...) rethrow the original error?

If in my code I do the following snippet: try { doSomething(); } catch (...) { doSomethingElse(); throw; } Will the throw rethrow the specific exception caught by the default ellipsis handler? ...

Can/Should you throw exceptions in a c# switch statement?

Hi All, I have an insert query that returns an int. Based on that int I may wish to throw an exception. Is this appropriate to do within a switch statement? switch (result) { case D_USER_NOT_FOUND: throw new ClientException(string.Format("D User Name: {0} , was not found.", dTbx.Text)); ...

Exception declared on ANTLR grammar rule ignored

I have a tree parser that's doing semantic analysis on the AST generated by my parser. It has a rule declared as follows: transitionDefinition throws WorkflowStateNotFoundException: /* ... */ This compiles just fine and matches the rule syntax at the ANTLR Wiki but my exception is never declared so the Java compiler complains abou...

How to: generate UnhandledException?

I use this code to catch the WinForm application UnhandledException. [STAThread] static void Main(string[] args) { // Add the event handler for handling UI thread exceptions to the event. Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); // Set the unhandled ...

Actionscript 3.0 - drag and throw with easing

I'm creating a map in flash and I would like to have a smooth movement similar to this: http://www.conceptm.nl/ I have made a start but I'm having trouble taking it to the next stage. My code currently throws the movieclip after the mouse is release but there is no easing while the mouse button is down. Any tips on how I would achieve...

throw exception

Why can't you throw an InterruptedException in the following way: try { System.in.wait(5) //Just an example } catch (InterruptedException exception) { exception.printStackTrace(); //On this next line I am confused as to why it will not let me throw the exception throw exception; } I went to http://java24hours.com, but it ...

Throwing an error in ActionScript and catching it with JavaScript

Hello, I am using the ExternalInterface to communicate between Flash and JavaScript using callbacks and the call method. I would like to throw an exception in ActionScript 3.0 and catch it in JavaScript and I was please wondering if there was anyway to do that? Thank you very much, Rudy ...

JavaScript Exception/Error Handling Not Working

This might be a little hard to follow. I've got a function inside an object: f_openFRHandler: function(input) { console.debug('f_openFRHandler'); try{ //throw 'foo'; DragDrop.FileChanged(input); //foxyface.window.close(); } catch(e){ ...

Why .NET exceptions are mutable?

I'm wondering why .NET exceptions classes from Base Class Library has some mutable members by default Why I can change the Source, HelpLink and values from Data, but can't change anything else like the Message? Why throwing the exception rewrites the StackTrace making it mutable too? Is appending the stack trace information to existing...

Returning after throwing exceptions

Is it in any way beneficial to return a value after throwing an exception? If not, can the return statement be left out and is it somehow possible to remove compiler error C4715: not all control paths return a value? Thanks in advance. Edit: (sample code) for (ushort i = 0; i < itsNumUnits; ++i) if (unitFormation[i] == unit) {...

Using "Throw" in a catchblock (and nothing else!)

Possible Duplicate: difference between throw and throw new Exception() I'm a programmer working on adding new functionality to legacy code. While debugging, I parsed over this Catch block, which got an angry "object not set to reference of object" notice from Visual Studio: catch(Exception ex) { Sp...

Is it okay to throw NullPointerException programatically ?

Hi, When there is a post-condition, that return value of a method must not be null, what can be done ? I could do assert returnValue != null : "Not acceptable null value"; but assertions could be turned off ! So is it okay to do if(returnValue==null) { throw new NullPointerException("return value is null at metho...