exception-handling

How to read DataInputStream until the end without needing to catch an EOFException?

≡放荡痞女 提交于 2019-12-13 22:09:21
问题 Suppose we have some binary data byte[] data that only contains Integers. If I wanted to read this data utilizing a DataInputStream , the only approach I can come up with is the following: DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); try { while (true){ int i = in.readInt(); } } catch (EOFException e) { // we're done! } catch (IOException e){ throw new RuntimeException(e); } What bugs me about this is that reaching the end of the stream is expected and it would

How to enable exception handling in mingw

浪尽此生 提交于 2019-12-13 19:45:06
问题 I am new to Mingw and C++ programming. I am trying to build a C++ project but getting following error. error: exception handling disabled, use -fexceptions to enable. Where I need to pass this -fexceptions parameter. When I am trying mingw32-make -fexceptions I am getting follwoing error. mingw32-make: exceptions: No such file or directory 回答1: Since you're using Qt, add "exceptions" to the CONFIG variable in your project file (the *.pro file): CONFIG += exceptions This should take care of

Exception not showing list values

大憨熊 提交于 2019-12-13 19:41:25
问题 In my Exception class, I pass an IEnumerable of IpAddresses. When the exception is thrown, this is what I see. How come it doesn't give me an option to see the values inside my IEnumerable? Here's the code that's causing the problem: public class CustomException : Exception { public List<string> IpAddresses { get; private set; } public CustomException(string message, IEnumerable<string> ipAddresses) : base(message) { IpAddresses = ipAddresses; } } Thanks in advance. 回答1: I figured out the

ruby on rails 3.1 global exception handler

你。 提交于 2019-12-13 19:16:13
问题 I'm developing an app with Rails 3.1.2 but I can't find some documentation that works with errors / exception (like 404) on this version of rails. i have tried things like: In application controller rescue_from ActiveRecord::RecordNotFound,ActionController::RoutingError, ActionController::UnknownController, ActionController::UnknownAction, :NoMethodError, :with => :handle_exception def handle_exception render :template => 'error_pages/error' end environment/development.rb config.consider_all

Handling user-defined exceptions from C++ DLL - .NET PInvoke/Marshalling

限于喜欢 提交于 2019-12-13 19:11:47
问题 I am working on WPF application which internally calls a C/C++ DLL using PInvoke. In the debug mode of the DLL, whenever error occurs the function throw an exception which is basically a structure defined containing specific error message and application code specific to module. This is different from the normal Win32 error logging. Now my problem is I want to catch the exception thrown by the DLL. If in use a try catch around the Marshalled function, .NET just informed me saying something

Rails 3.1 - in routes.rb, using the wildcard, match '*' is not catching any routes

爱⌒轻易说出口 提交于 2019-12-13 18:31:06
问题 In my pages_controller.rb file I have a not_found action. I want to have any route that is not matched by an entry in my routes.rb file to go to pages#not_found . Wanting to leverage a wildcard, I made this the last line of my routes.rb file: match '*' => 'pages#not_found' I'm basing this on what I read about wildcards in the ruby guide for routing (http://guides.rubyonrails.org/v3.1.0/routing.html). However it is not working. Instead of going to pages#not_found , I get: AcctionController:

How to change HTTP response and show an error message when exception happens in destructor?

不羁的心 提交于 2019-12-13 17:50:24
问题 I have a situation where a PHP function attempts to redirect the browser via an HTTP 302, but an exception is being thrown in a destructor called upon 'exit'ing. The actual code in question is the _doRedirect() method of SimpleSAML but here's a simplified situation: header('Location: http://somewhere.com', TRUE, 302); exit; // end script execution The 'exit' is triggering a destructor for an unrelated class and the error details are getting written out to the HTTP response... but no human

How to unit test to give coverage of exception branches

淺唱寂寞╮ 提交于 2019-12-13 17:46:25
问题 I write unit tests with JUnit4 and Mockito for my application and I want make full coverage. But I don't fully understand how cover exception branches. For example: try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } How I can invoke from tests exceptions? 回答1: While you may not easily be able to insert an exception into Thread.sleep in particular, because it's being called statically instead of against an injected instance, you can easily stub injected

C# - Infinite Loop at Exception Throwing?

主宰稳场 提交于 2019-12-13 16:43:25
问题 I have the following code: protected void ExecuteInTransaction(Action action) { using (SQLiteTransaction transaction = connection.BeginTransaction()) { try { action.Invoke(); transaction.Commit(); } catch(Exception) { transaction.Rollback(); throw; } } } While testing this class, I managed to throw an exception in order to test the catch branch . As I'm in Debug mode, I continue the execution of this throwing, to see how the calling class handles it , but the exception is never thrown by the

Catch C# WPF unhandled exception in Word Add-in before Microsoft displays error message

放肆的年华 提交于 2019-12-13 16:16:23
问题 I am developing a Microsoft Word Add-in using C# and WPF. In one of my windows, a helper class is throwing an exception in an event. I want the exception to bubble up to the window level so that I can catch it and display an error message to the user. Because it's in an event in the helper class, I can't just surround a method call in the window code with a try/catch block to catch it. Application.Current returns null so I cannot use the Application Dispatcher. I can use Dispatcher