try-catch

A more elegant way to control overwriting with try-except-else in python? or Can I do better than C-style code?

ぐ巨炮叔叔 提交于 2020-01-07 04:38:10
问题 I have code that makes a folder and places output files in it. I want to use a try-except-else block and an overwrite option, which can be set to True or False, so that in the case where the folder already exists and overwrite is set to false it will just print that the folder already exists, and in all other cases it will just execute without comment. The only solution I've come up with so far looks like this: def function( parameters, overwrite = False ): try: os.makedirs( dir ) except

try {inet_ntop($row['ip'])…} catch{gracefully} in PHP

血红的双手。 提交于 2020-01-06 19:47:52
问题 I am working on table that prints addresses from a MySQL database. I'm not sure I understand try/catch blocks very well. Old records have no IP address but new records do have an IP address in the table. The new records (with an IP address) print out fine, but only if I put it in a try catch like below: try { echo inet_ntop($row['ip']); } catch (Exception $e){ //echo 'Exception caught: ', $e->getMessage(), "\n"; echo "n/a"; } The records that don't have an IP in the IP field print out an ugly

java - where to put “return” in try, catch, finally block?

流过昼夜 提交于 2020-01-06 18:07:48
问题 I was tracking Spring Framework source and found some code which is not friendly to me. I thought I have to put "return" statement in finally block, but this code put that in try block. Here is the source code.(This is part of org.springframework.jdbc.core.JdbcTemplate) 629 public <T> T query( 630 PreparedStatementCreator psc, final PreparedStatementSetter pss, final ResultSetExtractor<T> rse) 631 throws DataAccessException { 632 633 Assert.notNull(rse, "ResultSetExtractor must not be null");

Skip errors in R for loops and also pause the process in each iteration

假如想象 提交于 2020-01-06 06:52:26
问题 I two questions regarding loops in R . 1) I'm using XML package to scrap some tables from the website and combine them using rbind . I'm using following command and it is working without issues if price data and tables are present in the given websites. url.list <- c("www1", "www2", "www3") for(url_var in url.list) { url <- url_var url.parsed <- htmlParse(getURL(url), asText = TRUE) tableNodes <- getNodeSet(url.parsed, '//*[@id="table"]/table') newdata <- readHTMLTable(tableNodes[[1]], header

Skip errors in R for loops and also pause the process in each iteration

只谈情不闲聊 提交于 2020-01-06 06:52:04
问题 I two questions regarding loops in R . 1) I'm using XML package to scrap some tables from the website and combine them using rbind . I'm using following command and it is working without issues if price data and tables are present in the given websites. url.list <- c("www1", "www2", "www3") for(url_var in url.list) { url <- url_var url.parsed <- htmlParse(getURL(url), asText = TRUE) tableNodes <- getNodeSet(url.parsed, '//*[@id="table"]/table') newdata <- readHTMLTable(tableNodes[[1]], header

Does try catch decrease efficiency?

…衆ロ難τιáo~ 提交于 2020-01-06 06:06:19
问题 Is there an efficiency difference between:- public boolean canDivisionBeDone(int iA, int iB){ try{ float a = iA/iB; }catch(Exception e){ return false; } return true; } and public boolean canDivisionBeDone(int iA, int iB){ if(iB == 0){ return false; }else{ float a = iA/iB; } return true; } If yes, why? 回答1: using try has no expenses by itself, but if the using block creates too much exceptions, you should try to review your code. Creating an exception in Java is a very slow operation. Expect

Cannot Catch Errors in Stripe payment gateway in Codeigniter 3

心不动则不痛 提交于 2020-01-06 04:35:11
问题 I am very new to stripe payment gateway integration. I am facing a problem on catching errors. I saw their official documentation for catching errors, but nothing is working. My payment is working fine and when I enter the correct information stripe takes my payment and successfully redirect to the success page, but the problem happens when I tried with wrong information it doesn't give me any error just shows HTTP 500 error (In production environment). When I set error_reporting(E_ALL) then

C# why throw errors [closed]

断了今生、忘了曾经 提交于 2020-01-05 13:17:31
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Im not getting the throw keyword, why use it? What are the benefits of it? As of now I've got this in my UI class: try { Classreference.MethodToRun(); } catch (Exception ex) { MessageBox.Show(ex.ToString(),

VBA Try and Catch (MS Outlook)

时光毁灭记忆、已成空白 提交于 2020-01-05 11:18:27
问题 I use the following function to monitor a public Outlook folder for new E-Mails to arrive: Public Sub Application_Startup() Set NewMail = Application.GetNamespace("MAPI").Folders(3).Folders(2).... End Sub For some reason, the path to this public folder changes over time in a weekly period. What changes is the number in .Folders(3) . It varies from 1 to 3. Apparently, to keep the function working and to catch the error, when the path changes, I want to implement a try and catch function such

Are try blocks necessary or even helpful for the “zero-cost” stack unwinding strategy?

柔情痞子 提交于 2020-01-05 08:36:39
问题 I came across the phrase "zero-cost" exception handling a few minutes ago and finally went to go look it up. I had seen the phrase a few times previously in an exceptions vs return codes context. Here's a short description of "zero-cost" and its alternative "setjmp/longjmp". https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Exception-Handling-Control.html GNAT uses two methods for handling exceptions at run-time. The setjmp/longjmp method saves the context when entering a frame with an