exception-handling

Proper way to adapt an exception with CompletableFuture

霸气de小男生 提交于 2020-01-15 10:09:57
问题 I am working on chaining CompletableFuture to adapt an exception. While I have something that is working, I don't understand why it works. @Test public void futureExceptionAdapt() throws ExecutionException, InterruptedException { class SillyException extends Exception { } class AdaptedException extends Exception { AdaptedException(SillyException silly) { } } CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> { sleepForThreeSeconds(); if (true) throw new

How to handle errors in client-server application using REST services?

旧城冷巷雨未停 提交于 2020-01-15 08:58:11
问题 QUESTION 1) How to handle errors in client-server application when using REST services? Could somebody help me with example code what is the best way to handle error messages in code below. How to catch exceptions in client side and/or server side in case of create-service for example? 2) How to forward user to different page in case of error and in case of success? CLIENT $('#btnSignup').click(function(){ var user = {"id": 10, "firstName": $('#firstName').val(), "lastName": $('#lastName')

Close multi threaded application with KeyboardInterrupt

丶灬走出姿态 提交于 2020-01-15 07:07:16
问题 I have an app with two threads. One is a pygame thread which runs a simple game, the other thread is a listening server which accepts messages which are used to control the game. Here is the stripped down pseudo code: class ServerThread(threading.Thread): def run(self): class SingleTCPHandler(SocketServer.BaseRequestHandler): try: while(1): ... #Receive messages from socket. Add them to pygame event queue ... except KeyboardInterrupt: sys.exit(0) ... ... class PygameThread(threading.Thread):

Close multi threaded application with KeyboardInterrupt

送分小仙女□ 提交于 2020-01-15 07:05:08
问题 I have an app with two threads. One is a pygame thread which runs a simple game, the other thread is a listening server which accepts messages which are used to control the game. Here is the stripped down pseudo code: class ServerThread(threading.Thread): def run(self): class SingleTCPHandler(SocketServer.BaseRequestHandler): try: while(1): ... #Receive messages from socket. Add them to pygame event queue ... except KeyboardInterrupt: sys.exit(0) ... ... class PygameThread(threading.Thread):

Python assertRaises on user-defined exceptions

主宰稳场 提交于 2020-01-15 05:15:30
问题 The following question was triggered by the discussion in this post. Assume two files ( foobar.py and foobar_unittest.py ). File foobar.py contains a class ( FooBar ) with two functions ( foo and bar ). Function bar raises a built-in exception, function foo a user-defined exception. # foobar.py class MyException(Exception): pass class FooBar: def __init__(self): pass def bar(self): raise ValueError('Hello World.') def foo(self): raise MyException('Hello World.') . # foobar_unittest.py import

Catching exceptions caused in different threads [duplicate]

ぐ巨炮叔叔 提交于 2020-01-15 05:09:35
问题 This question already has answers here : Catching unhandled exception on separate threads (3 answers) Closed 6 years ago . The below example is a simplification of my problem. An exception is thrown within a new thread. If im not handling this within the thread it is not caught by the outer try/catch and crashes my application. Is there any way to guarantee that I catch any exception that occurs. try { new Thread(delegate() { throw new Exception("Bleh"); // <--- This is not caught }).Start();

Pythonic Way To Check for A Parameter Type

拜拜、爱过 提交于 2020-01-14 19:25:51
问题 I'm working on a little side project for work and have made some classes and methods. One of the classes represents a shelf in our inventory and another represents each a bin on the shelf. I have a method to add a new bin to the shelf and I added some logic to make sure it was passed a Location object before it is added to the shelf (right now I'm using lists while I develop before moving everything to a DB). However I just read in a Python book that I have that it is usually better to handle

Best way to handle exception when joining a thread

为君一笑 提交于 2020-01-14 14:15:09
问题 For some reason I am confused over the following: Assume that I have Thread A that absolutely needs to execute after Thread B has completed its processing. A way to do this would be by Thread A joining Thread B . Trivial example: public class MainThread { public static void main(String[] args){ Thread b = new Thread (new SomeRunnable(args[0])); b.start(); try { b.join(); } catch(InteruptedException e) { } // Go on with processing } } My question is the following: What is the proper way to

General Problems With Geb (StaleElementReferenceException & Wait Timeouts)

爷,独闯天下 提交于 2020-01-14 13:51:03
问题 According to the "Book of Geb" I started to map our portal's web pages. I prefer to use variables defined within static content closure block and accessing them afterwards in page methods: static content = { buttonSend { $("input", type: "submit", nicetitle: "Senden") } } def sendLetter() { waitFor { buttonSend.isDisplayed() } buttonSend.click() } Unfortunately, sometimes I get an Geb waiting timeout exception (after 60 secs) or even worse I receive the well known

General Problems With Geb (StaleElementReferenceException & Wait Timeouts)

橙三吉。 提交于 2020-01-14 13:50:09
问题 According to the "Book of Geb" I started to map our portal's web pages. I prefer to use variables defined within static content closure block and accessing them afterwards in page methods: static content = { buttonSend { $("input", type: "submit", nicetitle: "Senden") } } def sendLetter() { waitFor { buttonSend.isDisplayed() } buttonSend.click() } Unfortunately, sometimes I get an Geb waiting timeout exception (after 60 secs) or even worse I receive the well known