exception-handling

Delphi: How to get (current code line, current unit, current function) without using Assertion?

别来无恙 提交于 2020-02-20 09:07:04
问题 I am trying to create a log system on my program that will log debugging messages on text files, and I want to save the exact place in the code where the log message called, but I don't want to use Assert function because it creates exceptions and this system is not for logging exceptions only, also I have to write some debugging info. example usning assert: procedure AnyProcedure(); begin try Assert(1=0); except on E: Exception do Log.AddLine('Log occurred is '+E.Message+' : Start');//Log

WebExceptionHandler : How to write a body with Spring Webflux

寵の児 提交于 2020-02-20 07:08:30
问题 I want to handle the Exception of my api by adding a WebExceptionHandler. I can change the status code, but I am stuck when i want to change the body of the response : ex adding the exception message or a custom object. Does anyone have exemple ? How I add my WebExceptionHandler : HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(toHttpHandler(routerFunction)) .prependExceptionHandler((serverWebExchange, exception) -> { exchange.getResponse().setStatusCode(myStatusGivenTheException);

WebExceptionHandler : How to write a body with Spring Webflux

有些话、适合烂在心里 提交于 2020-02-20 07:08:11
问题 I want to handle the Exception of my api by adding a WebExceptionHandler. I can change the status code, but I am stuck when i want to change the body of the response : ex adding the exception message or a custom object. Does anyone have exemple ? How I add my WebExceptionHandler : HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(toHttpHandler(routerFunction)) .prependExceptionHandler((serverWebExchange, exception) -> { exchange.getResponse().setStatusCode(myStatusGivenTheException);

junit testing - assertEquals for exception

爷,独闯天下 提交于 2020-02-18 13:55:50
问题 How can I use assertEquals to see if the exception message is correct? The test passes but I don't know if it hits the correct error or not. The test I am running. @Test public void testTC3() { try { assertEquals("Legal Values: Package Type must be P or R", Shipping.shippingCost('P', -5)); } catch (Exception e) { } } The method being tested. public static int shippingCost(char packageType, int weight) throws Exception { String e1 = "Legal Values: Package Type must be P or R"; String e2 =

PL/SQL exception handling: do nothing (ignore exception)

为君一笑 提交于 2020-02-18 05:43:19
问题 This is a question I am asked very frequently. Since I couldn't find any exact duplicate on stackoverflow, I thought I'd post it as a reference. Question: In PL/SQL, I know how to catch exceptions and execute code when they are caught, and how to propagate them to the calling block. For example, in the following procedure, the NO_DATA_FOUND exception is handled directly, while all other exceptions are raised to the calling block: CREATE OR REPLACE PROCEDURE MY_PROCEDURE() IS BEGIN do_stuff();

PL/SQL exception handling: do nothing (ignore exception)

我只是一个虾纸丫 提交于 2020-02-18 05:42:12
问题 This is a question I am asked very frequently. Since I couldn't find any exact duplicate on stackoverflow, I thought I'd post it as a reference. Question: In PL/SQL, I know how to catch exceptions and execute code when they are caught, and how to propagate them to the calling block. For example, in the following procedure, the NO_DATA_FOUND exception is handled directly, while all other exceptions are raised to the calling block: CREATE OR REPLACE PROCEDURE MY_PROCEDURE() IS BEGIN do_stuff();

Definition of checked Java exception?

走远了吗. 提交于 2020-02-13 05:22:37
问题 I see that one definition can be this: Generally RuntimeExceptions are exceptions that can be prevented programmatically. But that is still not the definition of a checked exception. I thought checked exceptions were "exceptions that can be handled at compile-time". Is that correct and/or can you tell me more? I also read this on the site, can you explain the quote? Many people say that checked exceptions (i.e. these that you should explicitly catch or rethrow) should not be used at all. Java

Definition of checked Java exception?

六眼飞鱼酱① 提交于 2020-02-13 05:22:31
问题 I see that one definition can be this: Generally RuntimeExceptions are exceptions that can be prevented programmatically. But that is still not the definition of a checked exception. I thought checked exceptions were "exceptions that can be handled at compile-time". Is that correct and/or can you tell me more? I also read this on the site, can you explain the quote? Many people say that checked exceptions (i.e. these that you should explicitly catch or rethrow) should not be used at all. Java

What did I do wrong in my function involving raising an exception?

£可爱£侵袭症+ 提交于 2020-02-07 06:29:59
问题 The instructions: Write a function validate_input(string) which takes a command string in the format 'command arg1 arg2' and returns the pair ('command', [arg1, arg2]), where arg1 and arg2 have been converted to floats. If the command is not one of 'add', 'sub', 'mul', or 'div', it must raise InvalidCommand. If the arguments cannot be converted to floats, it must raise InvalidCommand. Typical inputs and outputs: validate_input('add 2 3') -> ('add' [2. , 3.]) validate_input('hahahaha 2 3') ->

Chaining Tasks in csharp with success and fault handler

泪湿孤枕 提交于 2020-02-05 03:31:09
问题 Edit See the title "Problem" at the end within my question to crack this question down. Coming from nodejs where we could chain promises, in C# I'm seeing Async Tasks almost comparable. Here's my attempt. Edit - I can't mark my uber level caller methods as async as a dll based library is calling it Caller object public void DoSomething(MyRequest request) { Delegate.Job1(request) .ContinueWith(Delegate.Job2) .ContinueWith(Fault, TaskContinuationOptions.OnlyOnFaulted) .ContinueWith(Result); }