exception

Is there Match Or Exception Regex in .NET

I would like to do something like the below but throw an exception because there is no match. Is that possible? var val = Regex.Match("nomatchplz", "notgoingtomatch(.*)").Groups[1].Value; ...

Using Joda Date & Time API to parse multiple formats

I'm parsing third party log files containing date/time using Joda. The date/time is in one of two different formats, depending on the age of the log files I'm parsing. Currently I have code like this: try { return DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").parseDateTime(datePart); } catch (IllegalArgumentException e) { re...

Unexpected exception thrown when looking up user information

I have some code that is looking up group memberships from local groups on a machine. For each member, it tries to load some information about the user (eg. find a group and get the names of each of its members). The code: using (DirectoryEntry machine = new DirectoryEntry("WinNT://" + Environment.MachineName + ", Computer")) { usi...

Strange C++ exception "definition"

A student of mine submitted some C++ code similar to the following one. The code compiles and runs, but the throw statement produces the following message: terminate called after throwing an instance of 'int' If I make the function void the compiler complains invalid use of ‘void’ on the line that contains the throw statement...

C++ Exception Throw/Catch Optimizations

It seems to me that if you have some C++ code like this: int f() { try { if( do_it() != success ) { throw do_it_failure(); } } catch( const std::exception &e ) { show_error( e.what() ); } } The C++ compiler should be able to optimize the throw and catch into almost a simple goto. However, it seems to me from m...

Which Exception Should I Throw To Signal an Internal Error in my Program?

Which exception should I use when the program reaches a logic state that I "know" won't happen, and if it does, something is terribly bad. For example: int SomeFunction(int arg) { SomeEnum x = Whatever(arg, somePrivateMember); switch (x) { case SomeEnum.Value1: return SomeFunction1(); case SomeEnum.V...

Is it possible to retrieve the line number from an OleDbException caused by calling ExecuteNonQuery()?

We are calling ExecuteNonQuery on all files in a certain folder for version scripting and if there is a syntax error an exception is raised. I have been scanning MSDN for a way to get the line number but haven't been able to find anything yet. There is a 'SqlException' class which does contain the line number but the shared base class 'D...

Tomcat error when viewing page java.io.IOException: Stream broken

Hi, I get the below stack trace when I hit a servlet that retrieves some information from a database and populates a html template. I'm unclear if its an issue with writing to the disk or the connection to the browser? java.io.IOException: Stream broken at org.apache.tomcat.service.connector.AJP12RequestAdapter.readNextRequest(Ajp12Co...

How to get the number of exception the service has encountered in WCF?

How will I be able to count the number of exceptions thrown during the execution of a service? Right now I'm using behaviors to hook with the dispatchers using IOperationInvoker and IParameterInspector. But I need to know how can i count the faults and exceptions that occurs in a particular operation or the total occurrence in the whole ...

How do I catch ALL program aborting errors on iPhone?

I've written an unhandled error module for my iPhone app, but for some reason some errors are managing to bypass it. I have an exception handler and the following signal handlers set: NSSetUncaughtExceptionHandler(&handleException); signal(SIGILL, handleSignal); signal(SIGABRT, handleSignal); signal(SIGFPE, handleSignal); signal(SIGBUS...

ANTLR3 C Target with C++ Exceptions

I have some experience with ANTLR 2's C++ target, but have been hesitant to spend much time on ANTLR 3 because of my fears about exception safety. Sadly, ANTLR 3 only has a C target which produces C which is "C++ compatible." This does not seem to include C++ exception safety, based on the following: You can probably use [exception...

Way for C++ destructor to skip work when specific exception being thrown?

I have an object on the stack for which I wish its destructor to skip some work when the destructor is being called because the stack is being unwound due to a specific exception being thrown through the scope of the object on the stack. Now I could add a try catch block inside the scope of the stack item and catch the exception in ques...

How can I make Webkit Web Inspector to print exception when it caught?

I have questioned and got solution how to break on exception in Web Inspector: http://stackoverflow.com/questions/3315675/how-can-i-get-break-on-runtime-exceptionor-error-in-javascript-or-ecmascript Thanks klaaspieter. But I faced another problem. Web Inspector broke on exception, but does not print exception message until I continue ex...

Catching all exceptions in c#

Hi, I'm developing a GUI app in c#. Its a multithread app, and I would like to wrap all the threads (some of them I don't open e.g. NetClient.StartDownload which is none blocking function) with a try/catch . Statment so that if an exception is thrown an uncought, I could log it and report to base. I tried using Application.ThreadExcep...

Can I declare that a php function throws an exception?

Can I declare a function in php that throws an exception? For example: public function read($b, $off, $len) throws IOException ...

Powershell exit does not work

I am writing a script which checks for a registry value and and exits if is 0. (It will proceed if the value is 1.) if ((Get-ItemProperty -path HKLM:\SOFTWARE\ICT\LoginScript).proceed -eq 0) { $form.close() exit } When I run the script with the reg value at 0, it fails to exit and throws an ex...

C# get line number which thrown expection

Hi, in a catch block, how can I get the line number which thrown an exception? ...

Exception within function returning value for constructor...

Let's say I have class that acts as a "smart pointer" and releases some kind of system resource when destroyed. class Resource{ protected: ResourceHandle h; public: Resource(ResourceHandle handle) :h(handle){ } ~Resource(){ if (h) releaseResourceHandle(h);//external function, probably from...

What is the proper method of printing Python Exceptions?

except ImportError as xcpt: print "Import Error: " + xcpt.message Gets you a deprecation warning in 2.6 because message is going away. Stackoverflow How should you be dealing with ImportError? (Note, this is a built-in exception, not one of my making....) ...

java compiler says this exception is never thrown in body of corresponding try statement - but it _is_ thrown

I have the following code: try { //jaw-ws service port operation port.login(); } catch (Exception e) { logger.error("Caught Exception in login(): " + e.getMessage()); } When the above is run with an incorrect hostname, I get: Caught Exception in login(): HTTP transport error: java.net.UnknownHostException: abc That is c...