exception-handling

Rescue Timeout::Error from Redis Gem (Ruby)

安稳与你 提交于 2019-12-06 16:15:20
问题 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

Android Exceptions without Force Close

安稳与你 提交于 2019-12-06 15:59:57
问题 I might be missing something, but whenever an Exception gets thrown in Android (or java), my application ALWAYS force closes, and the whole program is terminated. However when something goes wrong in i.e. a database query, I just want to return to the Main menu. try { database.query(params); } catch (Exception e) { Log.e("Game", "Failed Loading Level", e); returnToMenu(); } } This for example force closes my program, I just want it to continue! 回答1: All android developer must have faced force

Handling all exceptions within global.asax

*爱你&永不变心* 提交于 2019-12-06 15:58:15
I'm trying to handle all application exceptions within global.asax for an MVC 3 project and whilst everything is working correctly within Cassini, as soon as I deploy to IIS 7.5, IIS starts taking control away from my application and handles many exceptions itself. This has the consequences of bypassing my custom logging and also returning ugly views. I have a similar approach to Darin's answer to this question . Here's what I'm using at the moment. protected void Application_Error(object sender, EventArgs e) { var app = (MvcApplication)sender; var context = app.Context; var exception = app

How to avoid a NullReferenceException

萝らか妹 提交于 2019-12-06 15:52:11
if (alMethSign[z].ToString().Contains(aClass.Namespace)) Here, I load an exe or dll and check its namespace. In some dlls, there is no namespace, so aclass.namespace is not present and it's throwing a NullReferenceException . I have to just avoid it and it should continue with rest of the code. If I use try-catch, it executes the catch part; I want it to continue with the rest of the code. Is aClass a Type instance? If so - just check it for null: if (aClass != null && alMethSign[z].ToString().Contains(aClass.Namespace)) Don't catch the exception. Instead, defend against it: string nmspace =

How to handle exception with PhpExcel?

前提是你 提交于 2019-12-06 15:42:05
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 is formula `=A2*A5` // and A8 is another `=A1/(A4*100)-A7` return $val; } catch (Exception $e) { echo $e

Python input validation: how to limit user input to a specific range of integers?

我怕爱的太早我们不能终老 提交于 2019-12-06 15:29:39
问题 Beginner here, looking for info on input validation. I want the user to input two values, one has to be an integer greater than zero, the next an integer between 1-10. I've seen a lot of input validation functions that seem over complicated for these two simple cases, can anyone help? For the first number (integer greater than 0, I have): while True: try: number1 = int(input('Number1: ')) except ValueError: print("Not an integer! Please enter an integer.") continue else: break This also doesn

Spring 5 Reactive - WebExceptionHandler is not getting called

感情迁移 提交于 2019-12-06 15:23:16
I have tried all 3 solutions suggested in what is the right way to handle errors in spring-webflux , but WebExceptionHandler is not getting called. I am using Spring Boot 2.0.0.M7 . Github repo here @Configuration class RoutesConfiguration { @Autowired private lateinit var testService: TestService @Autowired private lateinit var globalErrorHandler: GlobalErrorHandler @Bean fun routerFunction(): RouterFunction<ServerResponse> = router { ("/test").nest { GET("/") { ServerResponse.ok().body(testService.test()) } } } } @Component class GlobalErrorHandler() : WebExceptionHandler { companion object

Render failing to render correct template in rescue_from ActiveRecord::Rollback method

心已入冬 提交于 2019-12-06 15:14:45
I'm building the checkout page for an e-commerce site, and I have a fairly long transaction that creates a new User model and a new Order model. I wrapped the creation of these models in a transaction so that if validation for one fails, the other isn't hanging around in the database. Here's the trimmed-down code in my OrdersController: rescue_from ActiveRecord::Rollback, with: :render_new def render_new render action: 'new' end ActiveRecord::Base.transaction do @user = User.new params[:user] unless @user.save raise ActiveRecord::Rollback end //More stuff ... @order = Order.new params[:order]

Catch MySQL error in c++

限于喜欢 提交于 2019-12-06 15:11:35
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 have not found any reference to specific exception codes for MySQL use with catch statement. Apparently

Java sockets: best way to retry upon Connection Refused exception?

ぃ、小莉子 提交于 2019-12-06 15:05:43
Right now I'm doing this: while (true) { try { SocketAddress sockaddr = new InetSocketAddress(ivDestIP, ivDestPort); downloadSock = new Socket(); downloadSock.connect(sockaddr); this.oos = new ObjectOutputStream(downloadSock.getOutputStream()); this.ois = new ObjectInputStream(downloadSock.getInputStream()); break; } catch (Exception e) {} } downloadSock.connect(sockaddr) will generate a ConnectionRefused exception if the remote host is not listening on the socket. I'm running my code in a separate thread, so I'm not worried about blocking. Given this, is my method of retrying appropriate or