try-catch

catch errors within generator and continue afterwards

二次信任 提交于 2019-12-13 15:59:17
问题 I have an iterator which is supposed to run for several days. I want errors to be caught and reported, and then I want the iterator to continue. Or the whole process can start over. Here's the function: def get_units(self, scraper): units = scraper.get_units() i = 0 while True: try: unit = units.next() except StopIteration: if i == 0: log.error("Scraper returned 0 units", {'scraper': scraper}) break except: traceback.print_exc() log.warning("Exception occurred in get_units", extra={'scraper':

Can't catch 0xC0000005 exception in C#

僤鯓⒐⒋嵵緔 提交于 2019-12-13 15:16:35
问题 I am getting the following exception in my C#.Net program: A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll First-chance exception at 0x000007feff75121b in myapp.exe: 0xC0000005: Access violation reading location 0x0000000000000000. A first chance exception of type 'System.AccessViolationException' occurred in CustomMarshalers.dll An unhandled exception of type 'System.AccessViolationException' occurred in CustomMarshalers.dll Additional

C++ Try Catch inside loop

拟墨画扇 提交于 2019-12-13 12:30:08
问题 I have this C++ program with the following general structure 1st while (condition A == true) //some code for 1st loop 2nd while (condition B == true) //some code for 2nd loop try //some code for try catch //condition B == false (supposed to leave 2nd loop and go back to first loop) I want it to get out of 2nd loop when there's an exception and go back to 1st loop until condition B is tue again. As described above it doesn't work as I expect. What seems to be happening is that code gets stuck

pdo catch and output mysql errors

半世苍凉 提交于 2019-12-13 11:38:12
问题 Still trying to get my head around pdo. I have an insert statement that is executed with pdo. insert works great however if there is an error I would like it displayed to the user. I have the below try catch block. try{ $insertuser = $db->prepare('INSERT INTO `she_she`.`Persons` (`idnumber`,`addedby`,`firstname`, `middlename`, `surname`, `fullname`, `gender`, `birthdate`, `homelanguage`, `department`, `employeetype`, `employeestatus`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)'); $insertuser->execute

Index was outside the bounds of the array?

橙三吉。 提交于 2019-12-13 09:49:21
问题 I keep getting this message "System.IndexOutOfRangeException: Index was outside the bounds of the array." when attempting to run a program I built, that utilized an exception catcher. class StudentS { private List theStudentList; public bool PopulateStudents(string path) { theStudentList = new List<Student>(); bool flag = false; try { List<string[]> strArrayList = new List<string[]>(); using (StreamReader streamReader = new StreamReader(path)) { string str; while ((str = streamReader.ReadLine

Try-Catch inside a loop

百般思念 提交于 2019-12-13 09:35:47
问题 In the below code, I ask the user to give an integer input and if the input is 0 or a negative number, it loops again until the positive number is given. The thing is that if the users presses a letter, my code crashes and despite the fact that I used try-catch in a lot of ways nothing really worked. Any ideas? I used try-catch inside the loop, but it only worked for one letter input and not correctly. System.out.print("Enter the number of people: "); numberOfPeople = input.nextInt(); while

Does await new Task(async () => Actually halt execution until finished?

怎甘沉沦 提交于 2019-12-13 09:15:23
问题 I guess I'm not really understanding the await command in c#. I thought that using await would allow a method to continue processing and would would work in a separate thread and return a value once it completed however, I have the following code: public async Task<DatabaseActionResult> BackupToAzureAsync(DatabaseSchedule schedule) { try { foreach (var o in myObjects) { await new Task(async () => { try { //Do some stuff. } catch (Exception e) { throw; //Should this throw the exception to the

How to check whether inserting fails?

*爱你&永不变心* 提交于 2019-12-13 09:12:14
问题 Here is my script: try { $stmt = $db_con->prepare(" INSERT INTO mytable ( col ) VALUES ( ? ) "); $inserting = $stmt->execute( array('anything') ); if ( $inserting ) { echo 'successful'; } else { echo 'failed'; } } catch(PDOException $e){ echo 'failed'; } What's my question: All I want to know, else and catch are the same in my script? In other word when else executes? I think else never executes, because if $inserting == false then it jumps to the catch block, then else never run. Am I right?

unhandled exception at try catch affect performance [closed]

∥☆過路亽.° 提交于 2019-12-13 08:57:55
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I am working in a C# Desktop application I had made some code such that on execution of that code it falls into the catch block try { //come code } catch(exception ex) { } //some code 2 where I have not handled the exception because i want to excecute the code outside the catch block 'some code 2'

Try Catch Can't handle alter table

邮差的信 提交于 2019-12-13 08:46:38
问题 Why I this can't handle the alter table? Begin Try alter table nyork add [Qtr] varchar(20) End Try Begin Catch Print 'Column already exist' End Catch' 回答1: because one of them is a transact sql command (the try catch) and the other is a DDL statement. You'd probably do better off querying to see if the column exists before doing the alter statement. To do this with MSSQL, see How to check if a column exists in SQL Server table 回答2: You cannot do such a thing. TRY...CATCH can only handle