exception-handling

SocketChannel: java.io.IOException: An existing connection was forcibly closed by the remote host

試著忘記壹切 提交于 2019-12-23 17:27:26
问题 I'm using a SocketChannel with a network socket, and have to handle the expected exception of the other end of the socket closing the channel unexpectedly. The problem is, I get this IOException: java.io.IOException: An existing connection was forcibly closed by the remote host at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(Unknown Source) at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) at sun.nio.ch.IOUtil.read(Unknown Source) at sun.nio.ch

Python: can't see exception that is getting thrown

最后都变了- 提交于 2019-12-23 17:21:43
问题 I am running a unit test and I realize that there is an exception getting thrown. However, I am just not sure what exactly is getting thrown. from pt_hil.utilities.PT_HIL_Interface_Utils.widgets import PathPicker import unittest import wx class TestUM(unittest.TestCase): @classmethod def setUpClass(cls): print 'setUpClass called' cls.path_picker = PathPicker() print 'path_picker has been declared' def test_PathPicker(self): self.assertRaises(NotImplementedError, wx.UIActionSimulator

PHP, PDO, and Exceptions

南楼画角 提交于 2019-12-23 16:49:00
问题 I'm currently in a bit of a dilemma regarding PDO. I've recently switched to using it from my own custom database class as I want to take advantage of transactions. The problem I'm facing is how to throw exceptions from inside a block of code that is already wrapped with try/catch for PDO. Here is an example... try { // PDO code // Transaction start // Throw manual exception here if error occurs (transaction rollback too) // Transaction commit } catch (PDOException $e) { // Transaction

TPL Dataflow and exception handling in downstream blocks

耗尽温柔 提交于 2019-12-23 16:27:00
问题 I have the following pseudo code: var queue = new BufferBlock<int>(new DataflowBlockOptions { BoundedCapacity = 5 }); var a = new ActionBlock<int>(async item => { await Task.Delay(500); Trace.TraceInformation( $"Target 1: | Type: {typeof(int).Name} | Thread: {Thread.CurrentThread.ManagedThreadId} | Message: {item}"); // handling some logic but it throws if (item >= 5) throw new Exception("Something bad happened"); }, new ExecutionDataflowBlockOptions { BoundedCapacity = 1,

Capture and log / notify unhandled exceptions in a JSF based application

强颜欢笑 提交于 2019-12-23 15:44:16
问题 I would like to check and log all unhandled exceptions in my JSF web application using log4j. I read this post Log runtime Exceptions in Java using log4j and add a class that implements Thread.UncaughtExceptionHandler . but the method is not fired. What is the correct way to achieve this? 回答1: There's usually no means of an uncaught exception in a Java EE web application as the server ultimately catches any exception coming from the web application and displays it in case of synchronous HTTP

When to raise an exception or return null?

五迷三道 提交于 2019-12-23 15:35:20
问题 I have a few functions on Data access layer public Order RetrieveById(int id) public List<Order> RetrieveByStatus(OrderStatus status) Now i am bit confuse on exception raising. In case of RetrieveById function, id which is less than 1 is an invalid id therefore i feel like raising an exception. And i feel like returning null for the Id which doesn't exist in the database. Then it feels like i am over complicating. In case of RetrieveByStatus, i feel like returning a empty list when there is

SqlException constraint violation

守給你的承諾、 提交于 2019-12-23 15:09:39
问题 I'm working on an asp.net app. Is there a way, when catching a SqlException, to know which constraint was violated? 回答1: SqlException has a collection of SqlError objects: Errors. The SqlError have properties for error Number and you can compare this with the known constraint violation error numbers (eg. 2627). While is true that SqlException itself exposes a Number property, it is not accurate if multiple errors happen in a single batch and hence is better to inspect the Errors collection.

How to configure FOSRestBundle to not interfere with Custom Exception Controller

白昼怎懂夜的黑 提交于 2019-12-23 15:08:23
问题 I have just updated my Symfony 2.7 page to 2.8. Beside Symfony itself a number of other packages have been updated as well. FOSRestBundle has been updated from version 1.4 to 2.1. After the update the CustomExceptionController I configured for Twig does not work any more. Error like 404 or 500 show the default exception page instead of my custom page. This is the configuration: // app/config/config.yml ... twig: exception_controller: app.exception_controller:showAction // src/MyAppBundle

Entity Framework ORDER BY issue

青春壹個敷衍的年華 提交于 2019-12-23 13:15:35
问题 I'm attempting to build my first MVC 4 application using the entity framework. All I'm looking for is to create a drop down list with the value and text of each option set to the same value. This works, right up until I throw in the GroupBy() . Create.cshtml @Html.DropDownList("CustomerName",(SelectList)ViewData["companies"]); ticketController.cs ViewBag.companies = new SelectList(oc_db.company.Where(c => c.status == "ACTIVE") .OrderBy(c => c.name_1) .GroupBy(c=>c.name_1) , "name_1", "name_1"

Catching Sql Exception In Entity Framework4?What is the best practice?

雨燕双飞 提交于 2019-12-23 12:56:12
问题 What practices do you use in your datalayer to catch sql exceptions? Has anybody written a Generic Sql Exception handler where they catch the most common errors ? how do you do it any examples out there? Thanks 回答1: Handle unexpected exception by the underlying layer only Exceptions from your data layer (in this case Entity Framework) should be handled only by your business layer. The business layer can raise then (if necessary) a more high-level exception for your presentation layer (UI).