exception-handling

Optional in orElse-Branch throws Exception [duplicate]

匆匆过客 提交于 2019-12-19 06:45:38
问题 This question already has an answer here : Java 8's orElse not working as expected (1 answer) Closed 3 years ago . So I'm working with Optionals and came across a strange behaviour. I want to know if this is really an intendet "feature" or something...odd... Here is the given example: I've got a method with an Optional in whose orElse I want to evaluate an other optional. If the other Optional is not present, I'll raise an IllegalArgumentException: firstOptionalVar.orElse(secondOptionalVar

C++/CLI: Catching all (.NET/Win32/CRT) exceptions

佐手、 提交于 2019-12-19 06:29:09
问题 I know this is frowned upon, but I'm out of options here. I'm developing a C++/CLI app that has a bug that I'm unable to track down - mainly because it's bypassing my current crash handler: AppDomain::CurrentDomain->UnhandledException += gcnew UnhandledExceptionEventHandler(&LogAndExit); Application::ThreadException += gcnew ThreadExceptionEventHandler(&LogAndExit); Application::SetUnhandledExceptionMode(UnhandledExceptionMode::CatchException); try { Application::Run(gcnew frmMain()); } catch

Verifying exception messages with GoogleTest

一个人想着一个人 提交于 2019-12-19 06:04:33
问题 Is it possible to verify the message thrown by an exception? Currently one can do: ASSERT_THROW(statement, exception_type) which is all fine and good but no where can I find a way to test e.what() is really what I am looking for. Is this not possible via google test? 回答1: Something like the following will work. Just catch the exception somehow and then do EXPECT_STREQ on the what() call: #include "gtest/gtest.h" #include <exception> class myexception: public std::exception { virtual const

Throwing an exception while throwing an exception

早过忘川 提交于 2019-12-19 06:04:32
问题 This code: #include <iostream> #include <stdexcept> using namespace std; int throw_it() { throw range_error( "foo" ); } int main() { try { throw throw_it(); } catch ( exception const &e ) { cerr << e.what() << endl; return 0; } } prints foo when run, but is it guaranteed to do so? More specifically, does throwing an exception while in the process of throwing an exception result in defined behavior? And is that behavior to throw the most-recently-thrown exception (as the test code above does)?

Error and exception handling in php7

空扰寡人 提交于 2019-12-19 05:49:02
问题 Recently moved to php7. The following error occurs: argument 1 passed to MyClass\Throwable::exceptionHandler() must be an instance of Exception, instance of Error given And the respective class namespace MyClass; class Throwable { public function exceptionHandler(\Exception $exception) { //logic here } } As stated in docs most errors are now reported by throwing Error exceptions. Does it mean that I have to provide an instance of Error or even more general Throwable to the exception handler?

Option vs Exception in exception handling

怎甘沉沦 提交于 2019-12-19 05:46:51
问题 After using F# option type for a while, I realize that it could be used for handling exceptional cases. I can use either option or Exception in the following examples: The find functions from List/Array/Seq modules raise KeyNotFoundException in uncommon cases, while corresponding tryFind counterparts return None in those situations. When I do backtracking (in solving N-queens, Sudoku, etc), whenever a branch has no solution, I can either raise an exception and catch it later or return None to

Java resource closing

有些话、适合烂在心里 提交于 2019-12-19 05:45:09
问题 I'm writing an app that connect to a website and read one line from it. I do it like this: try{ URLConnection connection = new URL("www.example.com").openConnection(); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); String response = rd.readLine(); rd.close(); }catch (Exception e) { //exception handling } Is it good? I mean, I close the BufferedReader in the last line, but I do not close the InputStreamReader. Should I create a standalone

Make simple servlet filter work with @ControllerAdvice

独自空忆成欢 提交于 2019-12-19 05:25:11
问题 I've a simple filter just to check if a request contains a special header with static key - no user auth - just to protect endpoints. The idea is to throw an AccessForbiddenException if the key does not match which then will be mapped to response with a class annotated with @ControllerAdvice . However I can't make it work. My @ExceptionHandler isn't called. ClientKeyFilter import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Controller import javax

Error adding service reference: Type is a recursive collection data contract which is not supported

泪湿孤枕 提交于 2019-12-19 05:11:10
问题 I tried to add a service reference to a WCF service that resides in the same solution from an ASP.NET MVC 4 project but failed. I got a error saying: Custom tool error: Failed to generate code for the service reference 'XXX'. Please check other error and warning messages for details. The root warning is: Warning 9 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description

Can't catch exception inside AIF service

我与影子孤独终老i 提交于 2019-12-19 04:17:10
问题 I have created an AIF service in dynamics AX 2012, when I tested it by calling the entrypoint method from a job, it worked fine, but when it is deployed en the calls are comming from the soap UI, it crashes inside with an error: "Unhandled esception". While debugging I found out the unhandled exception is thrown inside my catch clause of my try catch statement. It gets inside the catch because the method I am calling inside the try clause thows an error. So does anyone know why I can catch