try-catch

How do I get the error message in Swift 2.0?

瘦欲@ 提交于 2019-12-18 18:48:51
问题 I used this method very much in Swift 1.2: NSURLConnection.sendSynchronousRequest(:_:_:_) but this is apparently deprecated in iOS9. It still works however but now it uses the new Swift 2.0 Error Handling and I don't know how I will get the error message if it fails, ex. if time runs out. I know I have to put it into a do-catch and then say try before the metho but I dont know how to catch the error message. do { let data = try NSURLConnection.sendSynchronousRequest(request, returningResponse

PHP check thrown exception type

情到浓时终转凉″ 提交于 2019-12-18 18:42:13
问题 Of course in PHP you can catch all thrown exceptions with: try{ /* code with exceptions */ }catch(Exception $e) { /* Handling exceptions */ } But is there a way to check the exception type of the thrown exception from inside the catch block? 回答1: You can use get_class: try { throw new InvalidArgumentException("Non Sequitur!", 1); } catch (Exception $e) { echo get_class($e); } 回答2: You can have multiple catch blocks to catch different Exception types. See below: try { /* code with exceptions *

PHP check thrown exception type

半腔热情 提交于 2019-12-18 18:42:02
问题 Of course in PHP you can catch all thrown exceptions with: try{ /* code with exceptions */ }catch(Exception $e) { /* Handling exceptions */ } But is there a way to check the exception type of the thrown exception from inside the catch block? 回答1: You can use get_class: try { throw new InvalidArgumentException("Non Sequitur!", 1); } catch (Exception $e) { echo get_class($e); } 回答2: You can have multiple catch blocks to catch different Exception types. See below: try { /* code with exceptions *

Clean way to catch errors from Azure Table (other than string match?)

自古美人都是妖i 提交于 2019-12-18 17:10:20
问题 I'd like to get a list of all the Azure Table errors and figure out a clean way to handle them in a try...catch block. For example, I'd like to not have to directly code and compare the InnerException message to String.Contains("The specified entity already exists") . What is the right way to trap these errors? 回答1: You could try looking at the values in the Response, rather that the inner exception. This is an example of one of my try catch blocks: try { return query.FirstOrDefault(); }

Capture Arbitrary Conditions with `withCallingHandlers`

我们两清 提交于 2019-12-18 13:14:35
问题 The Problem I'm trying to write a function that will evaluate code and store the results, including any possible conditions signaled in the code. I've got this working perfectly fine, except for the situation when my function (let's call it evalcapt ) is run within an error handling expression. The problem is that withCallingHandlers will keep looking for matching condition handlers and if someone has defined such a handler outside of my function, my function loses control of execution. Here

php - try, catch, and retry

僤鯓⒐⒋嵵緔 提交于 2019-12-18 11:00:42
问题 Sometimes my code breaks and it is out of my control How would I do the following? try { //do my stuff } catch { //sleep and try again } The code isn't that much, so it's all one function, so I didn't want to make and call another function if I didn't have to 回答1: You can try something like this: function exception_error_handler($errno, $errstr, $errfile, $errline ) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); $NUM_OF

Try-Catch-End Try in VBScript doesn't seem to work

丶灬走出姿态 提交于 2019-12-18 10:46:12
问题 I'm trying the following code: Try ' DOESN'T WORK Throw 2 ' How do I throw an exception? Catch ex 'What do I do here? End Try but I'm getting the error Statement expected in the catch clause. Does anyone know how I can catch/throw exceptions in VBScript using try/catch ? (I am not looking for solutions with On Error Do X .) 回答1: VBScript doesn't have Try/Catch. (VBScript language reference. If it had Try, it would be listed in the Statements section.) On Error Resume Next is the only error

How to avoid setting variable in a try statement

余生长醉 提交于 2019-12-18 09:49:07
问题 My problem is that I have to set a variable in a try statement otherwise I get a compile error. Later on I need to use that variable but it is now out of scope, or so I believe. I initialise the variable outside the try statement and set it to null, I thought that it might then be accessible outside, but I still get a NullPointerException . The code is below, with lots of it taken out to make reading easier - I know it's bad code, but I am new to Servlets and just wanted to see it running

Global Error handling using PartialView in MVC

冷暖自知 提交于 2019-12-18 09:46:31
问题 I have look at one of the perfect article on Exception handling in ASP.NET MVC and want to implement a method as on Method 6 in this article in order to reuse the same error page for all of other modal dialogs on error and exception situations. On the other hand, as I use popup window, I need to render a PartialView in my modal dialog instead of redirecting the page. Is it possible to do this? AJAX call: $.ajax({ type: "POST", url: '@Url.Action("Delete", "Person")', cache: false, dataType:

Set time out on simplexml_load_file

夙愿已清 提交于 2019-12-18 08:24:58
问题 I have this script which outputs an rss feed. Want I want to do is have it attempt to reach the rss url for something like 5 sec tops, and if it cannot then I want it to load a backup xml doc that is on the server. This is what I have and it is not working: <?php include '../php/connect.php'; $metaData = mysql_query("SELECT * FROM `siteinfo`") or die("couln't find table :("); $displayData = mysql_fetch_assoc($metaData); $url = $displayData['status']; $xml = file_get_contents($url); stream_set