exception-handling

How to determine if the Android Application was force closed?

有些话、适合烂在心里 提交于 2019-12-20 02:41:53
问题 I need to determine, if my application was force closed, crashed, or terminated normally. My question is: How would you do such a thing in Android environment. Handling exceptions is easy, I only need to Replace Thread.setDefaultExceptionHandler. The hard part is: how can i distinguish a force close shut down from a "normal" (like back press, or home button + lots of time, etc)? The reason is: We can synchronize the content of the local database, to a server. And we have a good reasons to

cython segmentation fault handling

笑着哭i 提交于 2019-12-20 02:38:46
问题 I am wrapping some C library, and I have one function which in some cases may result with segmentation fault. In that case I need to call second function, which will in that situation complete successfully. Does anyone knows how can I handle segmentation fault in cython? 回答1: A short example that might help (using signal ): example.h (assuming the Cython extension is named myext.pyx ) // Header autogenerated by Cython when declaring "public api" functions #include "../myext_api.h" void

PHPUnit Testing Exceptions for Laravel Resource Controllers

喜你入骨 提交于 2019-12-20 02:32:27
问题 Is it possible to test Exceptions with Laravel resource controllers? Every time I try to do the following: /** * @expectedException Exception * @expectedExceptionMessage Just testing this out */ public function testMyPost() { $response = $this->call('POST', '/api/myapi/', array('testing' => 1)); } I get: Failed asserting that exception of type "Exception" is thrown. I've tried this with \Exception and Exception . In my resource controller I have: public function store() { throw new \Exception

What does error_already_set in Boost.python do and how to handle exceptions similarly in Python C API

北城以北 提交于 2019-12-19 19:45:24
问题 I have been working on a project where I want to remove the boost dependencies and replace it with the Python C API. I spent some time understanding the Python C API and I saw this catch (error_already_set const &) I read the boost docs but it explains where it is used. But I want to know why it is needed and how can I achieve the same functionality using the native Python C api. 回答1: Boost throws error_already_set when a Python error has occurred. So if you see code like this: try { bp::exec

Exceptions are not caught in GCC program

空扰寡人 提交于 2019-12-19 18:39:25
问题 My project contains shared library and exe client. I found that my own exception class thrown from the library is not caught by client catch block, and program terminates with "terminate called after throwing an instance of ..." message. Continuing to play with the project, I found that any exception of any type is not caught. For example, this catch doesn't work: try { m_pSerialPort = new boost::asio::serial_port(m_IoService, "non-existing-port"); } catch(const boost::system::system_error& e

Catching exceptions as expected program execution flow control?

与世无争的帅哥 提交于 2019-12-19 13:46:09
问题 I always felt that expecting exceptions to be thrown on a regular basis and using them as flow logic was a bad thing. Exceptions feel like they should be, well, the " exception ". If you're expecting and planning for an exception, that would seem to indicate that your code should be refactored, at least in .NET... However. A recent scenario gave me pause. I posted this on msdn a while ago, but I'd like to generate more discussion about it and this is the perfect place! So, say you've got a

std::throw_with_nested expects polymorphic type in C++11?

北城余情 提交于 2019-12-19 12:51:50
问题 Why does this not compile (tried with Clang 3.4.2 and GCC versions 4.7.4, 4.8.3 and 4.9.1): #include <exception> struct E { E(int) {} }; int main() { std::throw_with_nested(E(42)); return 0; } Errors from GCC 4.9.1: In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/include/g++-v4/exception:163:0, from test.cpp:1: /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.1/include/g++-v4/bits/nested_exception.h: In instantiation of 'static const std::nested_exception* std::__get_nested_helper<_Ex>::_S

Throw custom Exceptions in Java/Android

旧巷老猫 提交于 2019-12-19 12:36:11
问题 I'm developing a custom Exception class, in which I have the following constructors: public class UserException extends Exception { string message; public UserException() { super(); } public UserException(String message, Throwable cause) { super(message, cause); this.cause = cause; this.message = message; } } And I create a new custom exception like this: private Camera.PreviewCallback SetPreviewCallBack() throws UserException { ....... // Something went wrong throw new UserException(

Checked Exception is compile time or runtime? [closed]

不羁的心 提交于 2019-12-19 12:20:14
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . I read about Checked exception that it is checked by compiler , but its runtime only. Is it correct? If it is correct then how? 回答1: Checked exceptions are checked at compile time to ensure you are handling them, either by catching them or declaring the containing method throws the exception. At

Proper catching of specific exceptions through web service

 ̄綄美尐妖づ 提交于 2019-12-19 11:26:43
问题 I am currently using a C# .NET Service in our client program. As part of the server design, several custom made exceptions are thrown to indicate specific errors (as in any normal desktop program). The problem is that the Web Service catches these errors and serializes them into a FaultException, with the actual exception (like NoRoomsAvailableException) written in the Message field. My question is whether there is a best practice for handling these errors. We have just begun working on this,