exception-handling

Python: Catching an exception works outside of a function but not inside a function

懵懂的女人 提交于 2019-12-08 05:40:23
问题 I have a strange problem which I can't solve myself. If I execute outside_func.py in two separate terminals, the second execution catches the BlockingIOError exception and the message is printed: outside_func.py import fcntl import time # Raise BlockingIOError if same script is already running. try: lockfile = open('lockfile', 'w') fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) except BlockingIOError: print('Script already running.') time.sleep(20) If I do the same with inside_func.py

Android vitals and exception handling

帅比萌擦擦* 提交于 2019-12-08 05:25:17
问题 I have been writing a simple Android application (one Activity). I would really like to gather crash reports from actual user sessions. I know there are some nice 3rd-party libraries. I also read that Google Play Console (Android vitals) should be providing some basic telemetry including crash reports. I was thinking that, to keep things simple, I would stick with the Android vitals for now. I was wondering whether there is anything I need to do on the Application side to get the crash

Exception while opening file

大城市里の小女人 提交于 2019-12-08 05:04:27
I have a VC++ application and in my application i have some basic file operations. Below is the defaulting code CStdioFile cFile; CFileException e; CString sReport; CString sHtmlfile = "testreport.html" OutputDebugString((sHtmlfile)); if (!cFile.Open(sHtmlfile,CFile::modeCreate | CFile::modeWrite, &e )) { } The problem is my application executes this piece of code every few minutes. and it works fine. After several runs of the code the cFile.Open() function fails. I tried to get the error message TCHAR szError[1024]; e.GetErrorMessage(szError,1024); OutputDebugString((szError)); The irony is

Unhandled exception while downloading web page using HttpWebRequest and StreamReader

六眼飞鱼酱① 提交于 2019-12-08 04:44:56
问题 This is a C# app using .NET 4.0. Background: I have been trying to refine a portion of an app which downloads files from multiple web servers. Everything is working pretty well except for an occasional situation wherein the remote computer closes the connection. I assume this may be due to a variety of factors, including network problems, power problems, etc. I'd like to simply skip the download in the event that the connection closes. However at present the application causes an exception

Catch MySQL error in c++

会有一股神秘感。 提交于 2019-12-08 04:19:56
问题 In C++, I am using mysql.h libraries and I do not manage to catch MySQL errors (for example, failure to insert due to conflict in primary key). I have tried #include <mysql.h> // ... try{ res = mysql_perform_query(conn, sqlIn); } catch (...) { // ... } but it still does not avoid aborting with: MySQL query error : Duplicate entry I am running the compiled c++ program using PuTTy interface and as the program aborts, it reproduces MySQL's error (regardless of whether I use TRY CATCH or not). I

Java - Exception handling - How to re-enter invalid input

£可爱£侵袭症+ 提交于 2019-12-08 04:14:11
问题 The exception handling only accepts double inputs. Therefore when the user enters "k" for example, it will say "Error! Please enter a number!". However instead of allowing the user to re-enter the input, it jumps onto the next input "Average impulse) How can I make it work so it will stay on the same line and allow to re-enter a value? //Main class public class Main { //Master class public static void main( String args[] ) //Standard header for main method { kbentry input = new kbentry(); /

Exceptions: Is this a good practice?

孤者浪人 提交于 2019-12-08 04:14:00
问题 This is written in PHP, but it's really language agnostic. try { try { $issue = new DM_Issue($core->db->escape_string($_GET['issue'])); } catch(DM_Exception $e) { throw new Error_Page($tpl, ERR_NOT_FOUND, $e->getMessage()); } } catch(Error_Page $e) { die($e); } Is nested try, catch blocks a good practice to follow? It seems a little bulky just for an error page - however my Issue Datamanager throws an Exception if an error occurs and I consider that to be a good way of error detecting. The

How to handle exception with PhpExcel?

谁说胖子不能爱 提交于 2019-12-08 04:13:09
问题 I'm using PhpExcel for my app and see a error. I've tried handling exception with try{}catch(){} but it doesn't work. How to handle exception with PhpExcel? Here is my code: function import($excelObj) { $sheet=$excelObj->getActiveSheet(); $cell = $sheet->getCellByColumnAndRow(1, 10);//assume we need calculate at col 1, row 10 try { //This line seen error, but cannot echo in catch. $val = $cell->getCalculatedValue(); // $cell contain a formula, example: `=A1+A6-A8` // with A1 is constant, A6

Exception while opening file

谁都会走 提交于 2019-12-08 03:56:32
问题 I have a VC++ application and in my application i have some basic file operations. Below is the defaulting code CStdioFile cFile; CFileException e; CString sReport; CString sHtmlfile = "testreport.html" OutputDebugString((sHtmlfile)); if (!cFile.Open(sHtmlfile,CFile::modeCreate | CFile::modeWrite, &e )) { } The problem is my application executes this piece of code every few minutes. and it works fine. After several runs of the code the cFile.Open() function fails. I tried to get the error

Using Python's 'with open()' To Write a Log, How Can I Write Exceptions to my Log?

半腔热情 提交于 2019-12-08 03:49:34
问题 I'm setting up a log file for a python script being run in a command window so that there's a record of all the input and output from the script. I'm using: with open("file.txt") as file: so that it will still save all the text it has written if an exception occurs. However I was wondering if there might be a way to get it to log the exception as well? Basically to write one last message and then close the file as the exit function? There seemed to be only a little documentation on with open(