exception-handling

Catch a fatal exception and continue

你。 提交于 2019-12-05 04:30:40
I know, that by its very definition, a fatal exception is supposed to kill the execution, and should not be suppressed, but here's the issue. I'm running a script that scrapes, parses and stores in a DB about 10,000 pages. This takes a couple of hours, and in rare cases (1 in 1000) a page fails parsing and throws a fatal exception. Currently, I'm doing this: for ($i=0;$i<$count;$i++) { $classObject = $classObjects[$i]; echo $i . " : " . memory_get_usage(true) . "\n"; $classDOM = $scraper->scrapeClassInfo($classObject,$termMap,$subjectMap); $class = $parser->parseClassInfo($classDOM);

Powershell $Error object not immediately populating inside PSM1 module

和自甴很熟 提交于 2019-12-05 04:10:23
I'm encountering a peculiar issue with Powershell. I'm catching an Exception in a catch block, but the global $Error object is not being populated. A trivial example, where this would behave as expected is this: function Bar { Foo } function Foo { try { $Error.Clear() throw "Error!" } catch { "Caught an error - current error count $($Error.Count)" } finally { "Cleaning up - current error count $($Error.Count)" } } Output is as you would expect if you call Bar Caught an error - current error count 1 Cleaning up - current error count 1 The code I'm having trouble with is nearly identical, except

catching exception from boost::filesystem::is_directory

▼魔方 西西 提交于 2019-12-05 03:52:29
I am currently catching errors from boost::filesystem::is_directory and showing the error to the user by calling "what()" on the exception. This gives the reason for failure but the error is strange to the user. For example: boost::filesystem::is_directory: Access is denied How can I catch the boost error and figure out what the actual cause is, so I can show a nicer error message? By "nicer error message" would you mean something like #include <iostream> #include <boost/filesystem.hpp> int main() { boost::filesystem::path p("/proc/1/fd/1"); try { boost::filesystem::is_directory(p); } catch

Do errors thrown within UncaughtExceptionHandler get swallowed?

我的未来我决定 提交于 2019-12-05 03:45:25
Thread.UncaughtExceptionHandler states that when the method which handles uncaught exceptions itself throws an exception, that exception will be ignored: void uncaughtException (Thread t, Throwable e): Method invoked when the given thread terminates due to the given uncaught exception. Any exception thrown by this method will be ignored by the Java Virtual Machine. However when I tested it, the JVM did not ignore the exceptions handled by the uncaught exception handler`: public static void main(final String args[]) { Thread.currentThread().setUncaughtExceptionHandler(new Thread

Is invalid user input a valid reason for throwing an exception?

回眸只為那壹抹淺笑 提交于 2019-12-05 03:44:09
According to the .NET Framework General Reference: Error Raising and Handling Guidelines exceptions should not be thrown during 'normal' operations. Is invalid user input to a web form, say the user enters a duplicate name, considered normal? !! IMPORTANT !!: I'm sure we pretty much all have an opinion on this, please include a reference to a reliable source. EDIT: A little more background: I'm questioning the approch to model validation advocated by a book I'm reading. The book is suggesting that you throw a custom exception from a repository when provided with invalid data to save. Now, this

Handling failures with Either -> Where is the stacktrace?

让人想犯罪 __ 提交于 2019-12-05 03:42:37
I heard from some people that in Scala we tend (like other functional languages) to not break the control flow... Instead by convention we return the error in an Either Left . But how do we get the stracktrace from that exception? For now i return in the Left a simple Error case class with a code, message and cause ( Error too). But if i have an error, i can't get the stacktrace. If my application become complexe it may be hard to find the code block that returned that Error ... The root cause is essential. So what do we do in practice? Should i return, instead of a custom Error , the java

Visual Studio 2013 “break on handled exceptions” not working, not breaking

醉酒当歌 提交于 2019-12-05 03:40:24
I am debugging an asp.net application on iisexpress.exe, I have configured visual studio 2013 to break on user-handled exceptions through the exception settings window but it still does not break when an exception is thrown. When I pause execution I can see on the Intellitrace window that a lot of exceptions were thrown but visual studio didn't break. Nadav Miller Ok, it seems it was because of the "Enable Just My Code" options was selected under Options->Debugging->General I don't know why but by default, it is checked. Any ideas? Should I leave it checked/unchecked? @Navad, how the debugger

How to set my own message in my custom exception in Java that can be retrieved my getMessage() BUT WITHOUT using the constructor, is there any way?

橙三吉。 提交于 2019-12-05 03:38:58
问题 I'm just learning about exception handling in Java. What I would like to know is rather than trying something like say: throw new Exception("My Message"); and String message=ex.getMessage(); System.out.println(message); Take a look at the code below , class ExceptionTest { public static void main(String[] args) { ExceptionTest t1=new ExceptionTest(); try { t1.riskyMethod();//call the risky or exception throwing method } catch(MyException myex) { System.out.println("Exception has been thrown")

Catch in Java a exception thrown in Scala - unreachable catch block

一笑奈何 提交于 2019-12-05 03:38:10
Scala doesn't have checked exceptions. However, when calling scala code from java, it's desirable to catch exceptions thrown by scala. Scala: def f()= { //do something that throws SomeException } Java: try { f() } catch (SomeException e) {} javac doesn't like this, and complains that "this exception is never thrown from the try statement body" Is there a way to make scala declare that it throws a checked exception? Use a throws annotation: @throws(classOf[SomeException]) def f()= { //do something that throws SomeException } You can also annotate a class constructor : class MyClass @throws

Get google test exception throw message [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-05 03:35:00
This question already has an answer here: Verifying exception messages with GoogleTest 1 answer I am using google Test framework for my project. I am throwing exception from the code as: throw DerivedClassException("message"); and in the test frame using as: ASSERT_THROW(commond(), DerivedClassException); I want to get message with what() API. Any way to get exact exception message of the exception. The only way to check the thrown exception is to catch it in the test : void test_foo( MyTest, TestException ) { try { functionThatThrowsException(); FAIL(); } catch( const DerivedClassException&