exception-handling

How to catch exception thrown by another thread in Java? [duplicate]

只愿长相守 提交于 2019-12-06 04:13:09
问题 This question already has answers here : How to catch an Exception from a thread (16 answers) Closed 2 years ago . I'm using a library that creates its own thread and it throws an exception. How can I catch that exception? The exception is thrown on the line marked below: ResourceDescriptor rd = new ResourceDescriptor(); rd.setWsType(ResourceDescriptor.TYPE_FOLDER); fullUri += "/" + token; System.out.println(fullUri); // >>> EXCEPTION THROWN ON THE FOLLOWING LINE <<< rd.setUriString(fullUri

Exception handling policy in libraries

一曲冷凌霜 提交于 2019-12-06 03:59:27
问题 When building a .NET library, what's your exception handling policy? In specific, what's your policy about handling exceptions inside library calls and exposing them to calling code? For example, Would you treat a library function as any other, thus letting all exceptions it can't handle flow out of it as-is? Would you create a custom exception for that library? Would you catch all exceptions and throw the library's exception instead? Would you set the original exception as the library's

Best practice error handling in JSP Servlets

梦想与她 提交于 2019-12-06 03:36:30
问题 I have a pretty simple web app using jsp/servlets over an Oracle database. The app only has a handful of pages right now, though it is growing. As of now, I dont have anything that shows users errors. For example, if the database connection fails, the page is just blank. I'm curious what the best practices are error handling? Should I print out a stack trace? Should all errors goto a default error page? Any advice or reference material would be appreciated. As you might tell, this is kind of

Memory exception while XDocument.Save()

偶尔善良 提交于 2019-12-06 03:19:20
I am trying to save an XDcoument to a thumb drive which doesnt have enough memory space available. (This is a special test condition for the app) Though the application is giving an exception like below, I cant get that in the try catch block around the XDocument.Save(filePath). Looks like it is a delayed throw. Is it a LINQ issue or am I doing something wrong?. alt text http://img211.imageshack.us/img211/8324/exce.png System.IO.IOException was unhandled Message="There is not enough space on the disk.\r\n" Source="mscorlib" StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String

How to catch exception when loading .NET WinForm app user.config file?

强颜欢笑 提交于 2019-12-06 03:04:41
问题 Sometimes in .NET (2.0) WinForm desktop apps which use the default configuration system, the user.config file will become corrupted and can't be loaded anymore (when the configuration system tries to load it, it'll throw a System.Xml.XmlException ). Putting aside the question of "why did the file get corrupted in the first place" (maybe it was cosmic rays, or HDD problems, or something else you can't control), the question then becomes "how can one catch this exception and do something

Declare method to throw an exception and subclass of this exception

不羁岁月 提交于 2019-12-06 03:04:18
问题 Is it meaningful to declare a method to throw an exception and a subclass of this exception, e.g. IOException and FileNotFoundException ? I guess that it is used in order to handle both exceptions by a caller method differently. However, is it possible to handle both exceptions if the method throws only the most generic i.e IOException ? 回答1: However, is it possible to handle both exceptions if the method throws only the most generic i.e IOException? Absolutely. You can still catch them

How to pass and receive objects using JNI

落花浮王杯 提交于 2019-12-06 03:03:28
I have an JAVA application in that I want to pass the object as a parameter to the C code using JNI and again I want to receive the object from the C code to JAVA using JNI . In JAVA side i have simply created an application and pass it to the method as shown bellow JlibFprint.fp_image_data fpimg = new JlibFprint.fp_image_data(); //object to be pass //fp_image_data is the static inner class of the class JlibFprint JlibFprint.fp_image_data fpimg1 = new JlibFprint.fp_image_data(); //received object This object is pass to the method like fpimg1 = JlibFprint.binary_image(fpimg); And JNI code for

Calculated properties do not throw exceptions in Powershell. What are the workaround possibilities?

懵懂的女人 提交于 2019-12-06 03:01:02
Apparently there is a by design quirk in Powershell that prevents exceptions that are thrown inside a Calculated Property Expression from bubbling up. All that happens is the value of the Calculated Property ends up being null. function Get-KBValue() { # Some Logic here that can throw an exception } .... Get-ChildItem C:\Test | Select-Object Name, CreationTime, @{Name="Kbytes"; Expression={ Get-KBValue }} If the Get-KBValue function throws an exception then the value of the Kbytes property is set to $null and the script continues. Possible workarounds: Use try/catch{break} within the

What to log when an exception occurs?

时光怂恿深爱的人放手 提交于 2019-12-06 02:58:41
问题 public void EatDinner(string appetizer, string mainCourse, string dessert) { try { // Code } catch (Exception ex) { Logger.Log("Error in EatDinner", ex); return; } } When an exception occurs in a specific method, what should I be logging? I see a lot of the above in the code I work with. In these cases, I always have to talk to the person who experienced the error to find out what they were doing, step through the code, and try to reproduce the error. Is there any best practices or ways I can

Handle Socket.ReceiveFrom with timeout without spamming console

柔情痞子 提交于 2019-12-06 02:29:27
I am writing a ServerLocator that basically broadcast a port to find a server which will respond with an IPEndPoint and I need the search to be able to timeout if nothing is found on the current IPHost and then move on with the next one. Right now I am doing something like this (I have removed some parts of this code so it only includes what is needed to display my problem. There is also some client bindings going on here) string serverIp = string.Empty; while(string.isNullOrEmpty(serverIp)) { foreach (IPAddress adress in ipHosts.AddressList) { using(Socket client = new Socket(AddressFamily