exception-handling

PDOException not being caught?

我们两清 提交于 2020-01-10 05:41:05
问题 I'm getting the following error in PHP: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (10061)' in C:\xampp\htdocs\project\Service\Database.class.php:26 Stack trace: #0 C:\xampp\htdocs\project\Service\Database.class.php(26): PDO->__construct('mysql:host=loca...', 'root', '', Array) #1 C:\xampp\htdocs\project\Service\Database.class.php(54): Service\Database::initialize() #2 C:\xampp\htdocs\project\index.php(15):

Suppressing PDO Warnings

馋奶兔 提交于 2020-01-10 05:09:05
问题 I'm trying to display a server status, based upon whether the database can be connected to or not. With the old school mysql_connect() and mysqli_connect() it was easy. I'm trying to stay modern, so I'm using PDO, but I can't figure out how-to suppress the default warning. From what I can tell, you need to use the getMessage() function for it to print the PDO warning, but I'm not using it. Here's my code: 8 $dbstatus = 1; 9 try { 10 $db = new PDO($dbms . ':host=' . $dbhost . ';port=' .

Receiving SIGINT and exception Handles in Linux

落爺英雄遲暮 提交于 2020-01-10 04:38:06
问题 Let's say we have a program in C that uses the sleep() function The program executes and goes to sleep. Then we type ctrl-c to send a SIGINT signal to the process. We know that the default action upon receipt of a SIGINT is to terminate the process, we also know that the sleep() function resume the process whenever the sleeping process receives a signal. And my textbook says in order to allow sleep() function to return, we must install a SIGINT handler like this: void handler(int sig){ return

In java,what if both try and catch throw same exception and finally has a return?

时光总嘲笑我的痴心妄想 提交于 2020-01-09 11:45:36
问题 public class Abc { public static void main(String args[]) { System.out.println(Abc.method()); } static int method() { try { throw new Exception(); } catch(Exception e) { throw new Exception(); } finally { return 4; } } } Why is the return value 4? 回答1: That's the way finally works. The snippet try { throw new Exception(); } catch(Exception e) { throw new Exception(); } will complete abruptly , but the finally clause will kick in and when it returns it discards the original reason for

In java,what if both try and catch throw same exception and finally has a return?

吃可爱长大的小学妹 提交于 2020-01-09 11:42:53
问题 public class Abc { public static void main(String args[]) { System.out.println(Abc.method()); } static int method() { try { throw new Exception(); } catch(Exception e) { throw new Exception(); } finally { return 4; } } } Why is the return value 4? 回答1: That's the way finally works. The snippet try { throw new Exception(); } catch(Exception e) { throw new Exception(); } will complete abruptly , but the finally clause will kick in and when it returns it discards the original reason for

WebBrowser control throws seemingly random NullReferenceException

孤者浪人 提交于 2020-01-09 10:36:30
问题 For a couple of days I am working on a WebBrowser based webscraper. After a couple of prototypes working with Threads and DocumentCompleted events, I decided to try and see if I could make a simple, easy to understand Webscraper. The goal is to create a Webscraper that doesn't involve actual Thread objects. I want it to work in sequential steps (i.e. go to url, perform action, go to other url etc. etc.). This is what I got so far: public static class Webscraper { private static WebBrowser _wb

WebBrowser control throws seemingly random NullReferenceException

ぐ巨炮叔叔 提交于 2020-01-09 10:34:15
问题 For a couple of days I am working on a WebBrowser based webscraper. After a couple of prototypes working with Threads and DocumentCompleted events, I decided to try and see if I could make a simple, easy to understand Webscraper. The goal is to create a Webscraper that doesn't involve actual Thread objects. I want it to work in sequential steps (i.e. go to url, perform action, go to other url etc. etc.). This is what I got so far: public static class Webscraper { private static WebBrowser _wb

Code reuse in exception handling

拜拜、爱过 提交于 2020-01-09 09:12:00
问题 I'm developing a C api for some functionality written in C++ and I want to make sure that no exceptions are propagated out of any of the exported C functions. The simple way to do it is making sure each exported function is contained in a: try { // Do the actual code } catch (...) { return ERROR_UNHANDLED_EXCEPTION; } Let's say I know one exception that is often missed inside the C++ code is std::bad_alloc and I want to treat it specially I'd write something like this instead: try { // Run

Best way to check for inner exception?

老子叫甜甜 提交于 2020-01-09 04:13:40
问题 I know sometimes innerException is null So the following might fail: repEvent.InnerException = ex.InnerException.Message; Is there a quick ternary way to check if innerException is null or not? 回答1: Is this what you are looking for? String innerMessage = (ex.InnerException != null) ? ex.InnerException.Message : ""; 回答2: Great answers so far. On a similar, but different note, sometimes there is more than one level of nested exceptions. If you want to get the root exception that was originally

Setting Precedence of Multiple @ControllerAdvice @ExceptionHandlers

半腔热情 提交于 2020-01-08 11:36:08
问题 I have multipler classes annotated with @ControllerAdvice , each with an @ExceptionHandler method in. One handles Exception with the intention that if no more specific handler is found, this should be used. Sadly Spring MVC appears to be always using the most generic case ( Exception ) rather than more specific ones ( IOException for example). Is this how one would expect Spring MVC to behave? I'm trying to emulate a pattern from Jersey, which assesses each ExceptionMapper (equivalent