exception-handling

Throwing an exception in catch block

冷暖自知 提交于 2019-12-11 13:59:44
问题 I can't understand how to handle an exception in a method which returns value, in my case the value of Person[] type. I tried to do as written here - Creating and Throwing Exceptions, but I'm still getting an exception in - throw icex; line. Could someone please give me a hint? I also tried to return null in catch block, instead of throw, but I only get another exception.(I'm using ArrayList instead of List intentionally) static ArrayList CreateNonGenericList() { ArrayList personList = new

exception_handling -> not as robust as simply logging error?

ぃ、小莉子 提交于 2019-12-11 13:57:49
问题 Exception handling in php ... I have noticed some quirks that seem to make it a tedious matter to implement properly. First off, most legacy php functions do not throw exceptions per se, it seems one has to implement set_error_handler and have the callback throw functions. Ok. Minor annoyance but let's see what gives. OH! Great, now everything throws an exception, and of course, the worst part: uncaught exceptions halt the script. So, kind of got to figure after reading the manual and other

.NET - log exceptions to db using multiple SqlParameters and specify what goes in each db column

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 13:48:02
问题 I'm following KudVenkat 's tutorial for logging exceptions to the database in .NET : http://csharp-video-tutorials.blogspot.com/2012/12/logging-exception-to-database-part-75.html His way is good for storing one thing - an ExceptionMessage string containing Exception Message, Exception Type, Stack Trace, etc - into one column - the @exceptionMessage column. I'm trying to split this full Exception Message up into parts, such as ExceptionType (to the @exceptionType column), exceptionMessage (to

Java Scoping & Visibility Rules

隐身守侯 提交于 2019-12-11 13:43:22
问题 I am coming back to writing code in Java after a long gap - most of my coding work over the past few years has been in PHP & JavaScript - and am discovering that I have to work harder to satisfy the Java compiler which is far more rigorous about issues such as variable scope and exception handling. A piece of code that caused me some trouble is shown below File file = new File(path, fname); FileOutputStream stream = null; try { stream = new FileOutputStream(file); stream.write(tosave.getBytes

Print Stacktrace into Textarea in JavaFX

情到浓时终转凉″ 提交于 2019-12-11 13:37:15
问题 I would like to print the stacktrace of a throwable into a Textarea Something like this: textArea.setText(throwableElement.toString() + "\n" + throwableElement.printStackTrace()); Is that possible? I hope you can help me Thanks 回答1: You can do StringWriter stackTraceWriter = new StringWriter(); throwableElement.printStackTrace(new PrintWriter(stackTraceWriter)); textArea.setText(throwableElement.toString() + "\n" + stackTraceWriter.toString()); 来源: https://stackoverflow.com/questions/33411873

Python while loop to check if file exists

旧街凉风 提交于 2019-12-11 13:22:37
问题 Hey guys I'm coding something that seems really weird to me, and I can't logically figure out how to implement it, and I feel like if I do it'll be cpu melting - so I figure I'd ask people who really know. What I want to do is check if a file exists, if it doesn't, perform an action, then check again, until the file exists and then the code passes on with that. I've tried Googling to little avail. Thanks to anyone who helps! 回答1: For simplicity, I would implement a small polling function,

Should Exception catch DeadlineExceededError exceptions?

◇◆丶佛笑我妖孽 提交于 2019-12-11 13:17:16
问题 I have the code like below: try: response = urlfetch.Fetch(url, deadline=60, headers=headers, follow_redirects=False) except Exception, error_message: logging.exception('Failed, exception happened - %s' % error_message) but sometimes it fails with DeadlineExceededError ? Should not this DeadlineExceededError be caught by my code? The exception details: Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266

How to NOT breaking on an exception?

廉价感情. 提交于 2019-12-11 13:12:00
问题 I've got something like this: try { instance.SometimesThrowAnUnavoidableException(); // Visual Studio pauses the execution here due to the CustomException and I want to prevent that. } catch (CustomException exc) { // Handle an exception and go on. } anotherObject.AlsoThrowsCustomException(); // Here I want VS to catch the CustomException. In another part of code I have multiple occurencies of situations where CustomException is thrown. I would like to force the Visual Studio to stop breaking

Exceptions vs “if” in C#

久未见 提交于 2019-12-11 13:06:58
问题 I have a control flow question. In my company we create a lot of bool methods that return false if there was an error. Example: public bool Foo(string path, string fileName, ref string error) { if (path == null) { error = "path is null"; return false; } path += fileName; return true; } As you can see it's ugly. I want to use it with exceptions like so: public voidFoo(string path, string fileName, ref string error) { if (path == null) { throw new SomeException("Path is null."); } path +=

How to effectively handle any kind of exceptions?

这一生的挚爱 提交于 2019-12-11 12:54:49
问题 Exception handling is the most useful mechanism to save the application from the crash. Even most of us following the exception handling mechanism. Even I see many of still getting the exceptions. Are we handling the exceptions in a way that supposed to? My question is, What is best way to handle any kind of exception? I want to make few things clear. When I say handling an exception that does not only mean that capturing appropriate exception message and showing or logging it. Rather, it