exception-handling

Python Exception Handling with in a loop

你说的曾经没有我的故事 提交于 2020-01-13 19:06:44
问题 An exception occurs when my program can't find the element its looking for, I want to log the event within the CSV, Display a message the error occurred and continue. I have successfully logged the event in the CSV and display the message, Then my program jumps out of the loop and stops. How can I instruct python to continue. Please check out my code. sites = ['TCF00670','TCF00671','TCF00672','TCF00674','TCF00675','TCF00676','TCF00677']` with open('list4.csv','wb') as f: writer = csv.writer(f

Logging camel exceptions and sending to the dead letter channel

不羁岁月 提交于 2020-01-13 09:43:30
问题 I have a Camel route, running within Karaf, for which I've added a Dead Letter Channel. This is to handle cases where the route fails and I want to keep the problem message and log the cause. I can't throw the exception back to the calling application as I'm handling some processing asynchronously. From reading the documentation and trying a number of cases, it's not clear to me how to both log the exception into Karaf's log and deposit the original message onto the dead letter queue. Here's

Is it always a bad practice to catch System.Exception?

北慕城南 提交于 2020-01-13 07:58:05
问题 Please consider the following piece of code, which throws three different exceptions (namely, System.Configuration.ConfigurationErrorsException , System.FormatException and System.OverflowException ): int SomeInt = Convert.ToInt32(ConfigurationManager.AppSettings["SomeIntValue"]); The exceptions are different, and so in practice I should have three different catch blocks to handle each particular exception. However, in this particular case, all exceptions are handled the same way: a log is

DBI: raiseerror in eval

一曲冷凌霜 提交于 2020-01-13 06:24:09
问题 This question refers to this comment from Ikegami: [...] But if you're going to put an eval around every statement, just use RaiseError => 0. [...] in this thread. What do I gain, if I set RaiseError to 0 in such situations? #!/usr/bin/env perl use warnings; use 5.10.1; use DBI; my $db = 'my_test_sqlite_db.sqlite'; open my $fh, '>', $db or die $!; close $fh or die $!; my ( $dbh, $sth ); eval { $dbh = DBI->connect( "DBI:SQLite:dbname=$db", "", "", {} ); }; if ( $@ ) { print $@ }; my $table =

Render View from AppExceptionHandler

时光怂恿深爱的人放手 提交于 2020-01-13 03:44:09
问题 I'm working with CakePHP 2.0 and want to handle a ForbiddenException. I've followed the example explained at the CakePHP Cookbook. My exception is now caught at the AppExceptionHandler but I don't know how to move from here. I want to render a relevant View but $this is not available. Does anyone have a starting point for me? Edit: My code so far is identical to the Cookbook example: In app/Config/core.php Configure::write('Exception.handler', 'AppExceptionHandler::handle'); In app/Config

Using finally block vs writing code after the try/catch block

倖福魔咒の 提交于 2020-01-12 18:23:12
问题 As I understand, the following 2 examples should do the same thing. Why is the 1st considered better? 1: try { riskyMethod(); } catch(Exception e) { //handle exception } finally { cleanUp(); } 2: try { riskyMethod(); } catch(Exception e) { //handle exception } cleanUp(); EDIT: The example is in Java, but I'm wondering about the concept of a finally block in general, as used in any language 回答1: Well, for one thing if the "handle exception" part throws an exception itself, cleanup won't occur.

Using finally block vs writing code after the try/catch block

坚强是说给别人听的谎言 提交于 2020-01-12 18:22:08
问题 As I understand, the following 2 examples should do the same thing. Why is the 1st considered better? 1: try { riskyMethod(); } catch(Exception e) { //handle exception } finally { cleanUp(); } 2: try { riskyMethod(); } catch(Exception e) { //handle exception } cleanUp(); EDIT: The example is in Java, but I'm wondering about the concept of a finally block in general, as used in any language 回答1: Well, for one thing if the "handle exception" part throws an exception itself, cleanup won't occur.

JUnit 4 and Suspend-on-Exception

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-12 14:29:14
问题 When an uncaught exception is thrown in my code, I am used to having the debugger stop at the throwing statement so that I can examine the local variables and the members of all objects involved at the moment that the exception was thrown. With IntelliJ Idea this can be accomplished by going to Run , View Breakpoints , selecting the Exception Breakpoints tab, checking Any exception , and making sure that the Caught exception checkbox is unchecked, while the Uncaught exception checkbox is

How to jump back to the line of code that threw exception in Visual Studio 2010 debugger?

廉价感情. 提交于 2020-01-12 14:00:44
问题 Using the Visual Studio 2010 debugger, I am familiar with using the Call Stack window to see where the currently executing function was invoked from. I'm working with some applications that have rather large try blocks. Supposing that I pause execution of the code at a break point in the catch block, what is the simplest way to tell which line in the try block the exception was raised from? I do know that the "Stack Trace" includes details such as the line number, but is there an easier way,

How to jump back to the line of code that threw exception in Visual Studio 2010 debugger?

六月ゝ 毕业季﹏ 提交于 2020-01-12 14:00:35
问题 Using the Visual Studio 2010 debugger, I am familiar with using the Call Stack window to see where the currently executing function was invoked from. I'm working with some applications that have rather large try blocks. Supposing that I pause execution of the code at a break point in the catch block, what is the simplest way to tell which line in the try block the exception was raised from? I do know that the "Stack Trace" includes details such as the line number, but is there an easier way,