exception-handling

Checking module name inside 'except ImportError'

假如想象 提交于 2019-12-04 22:56:38
try: import MySQLdb # some action except ImportError as err: # fallback code PyCharm gives a code inspection warning on that: 'MySQLdb' in try block with 'except ImportError' should also be defined in except block This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items. Ok, I thought the warning is reasonable, because the fallback code assumes that 'MySQLdb' is not installed, while it could be some different error that

return statement in java exception handling [duplicate]

雨燕双飞 提交于 2019-12-04 22:48:47
问题 This question already has answers here : Does a finally block always get executed in Java? (47 answers) Java's return value in try-catch-finally mechanism (4 answers) Closed 6 years ago . If execution doesn't cause exception then control goes to finally block. So is the return statement in try block is being ignored by JVM? . Or if exception occurs then control goes to catch block there also it ignored return statment and control go to finally block and return from finally public class Helper

Heap corruption when returning from function inside a dll

馋奶兔 提交于 2019-12-04 22:45:31
问题 I have a function with a prototype like the following: void function(std::string str); This function is called in my main function in another program that loads and uses that dll. function("some string value here"); When returning from this function I get heap corruption error: Windows has triggered a breakpoint in program.exe. This may be due to a corruption of the heap, which indicates a bug in program.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while

Alternatives to SmartAssembly for exception handling and reporting?

不羁的心 提交于 2019-12-04 22:42:50
问题 I was happy with the SmartAssembly solution for exception handling, but I reported an issue on Red Gate forum and is not being solved yet. What alternatives exists to SA? I mean with similar features (hosting your reports, sending you e-malis, etc)? 回答1: SmartAssembly has two main features - obfuscation and error reporting. If you are using obfuscation, there are several free and commercial alternatives. The list linked to by TrueWill shows a good selection. For exception handling, the only

How to re-raise pl/sql exception in exception handling block?

余生长醉 提交于 2019-12-04 22:41:53
I have the following procedure which is used by some applications: procedure p1 is begin bla bla bla; end; But there is no exception handling block. So applications were written according this feature. Now I need to log errors in p1. But it shouldn't affect applications that use this procedure. Something like this: procedure p1 is begin bla bla bla; exception when others then log_error(sqlcode, sqlerrm); raise_new_exception (sqlcode, sqlerrm); end; In case of raise_application_error first parameter should be in range [-20000, -20999]. So if there raises exception no_data_found, it cannot raise

Add new field in body exception spring rest

半城伤御伤魂 提交于 2019-12-04 22:24:52
问题 I want to handle exceptions in my Rest spring boot application. I know that with @ControllerAdvice and ResponseEntity I can return a custom object that will represent my error, but what I want is to add a new field to the body of the exesting exception that's all. I created a custom Exception that inherit RuntimeException with an extra attribute, a list of string : @ResponseStatus(HttpStatus.CONFLICT) public class CustomException extends RuntimeException { private List<String> errors = new

declare a method always throws an exception?

故事扮演 提交于 2019-12-04 22:20:19
I have a method like... int f() { try { int i = process(); return i; } catch(Exception ex) { ThrowSpecificFault(ex); } } This produces a compiler error, "not all code paths return a value". But in my case ThrowSpecificFault() will always throw (the appropriate) exception. So I am forced to a put a return value at the end but this is ugly. The purpose of this pattern in the first place is because "process()" is a call to an external web service but need to translate a variety of different exceptions to match a client's expected interface (~facade pattern I suppose). Any cleaner way to do this?

Catch 401 error in Rails with Devise when user has multiple windows open

情到浓时终转凉″ 提交于 2019-12-04 21:41:36
Scenario is this: User has 2 windows on which s/he is logged in. S/he logs out of one, stays logged in on the other, and then on the latter, triggers some action, say a form submission. Initially, what happened is that it threw a invalid authenticity token error. I've updated the protect_from_forgery in ApplicationController to be with: :null_session so that instead of the Exception it throws a 401. Great! Now for step 2, rather than the user just seeing a line of text saying You need to sign in or sign up before continuing. , I'd like to redirect him/her back to the sign in page. This is

Rescue Timeout::Error from Redis Gem (Ruby)

夙愿已清 提交于 2019-12-04 20:59:36
I need to rescue a Timeout::Error raised from a the Redis library but i'm running into a problem, rescuing that specific class doesn't seem to work. begin Redis.new( { :host => "127.0.0.X" } ) rescue Timeout::Error => ex end => Timeout::Error: Timeout::Error from /Users/me/.rvm/gems/ree-1.8.7-2011.03@gowalla/gems/redis-2.2.0/lib/redis/connection/hiredis.rb:23:in `connect' When i try to rescue Exception it still doesn't work begin Redis.new( { :host => "127.0.0.X" } ) rescue Exception => ex end => Timeout::Error: Timeout::Error from /Users/me/.rvm/gems/ree-1.8.7-2011.03@gowalla/gems/redis-2.2.0

program to print 1-100 prime number and throw exception for composite number in given range

南楼画角 提交于 2019-12-04 20:56:25
i have made a program to print 1-100 prime numbers. please help me to throw exception for composite number in range of 1-100 numbers. i am a beginner so any help will be appreciated. public static void main(String[] args) { System.out.println("Prime numbers from 1 - 100 are :"); int i = 0; int x = 0; for (i = 1; i <= 100; i++) { int ctr = 0; for (x = i; x >= 1; x--) { if (i % x == 0) { ctr = ctr + 1; } } if (ctr == 2) { System.out.println(i); } } } I'd rather implement isPrime method and call it public static boolean isPrime(int value) { if (value <= 1) return false; // There's only one even