exception-handling

C# equivalent to VB.NET's Catch…When

99封情书 提交于 2019-12-30 06:00:13
问题 In VB.NET I often Catch…When : Try … Catch e As ArgumentNullException When e.ParamName.ToUpper() = "SAMPLES" … End Try Is there a C# equivalent to Catch…When ? I don't want to resort to using an if statement inside a catch if possible. 回答1: This functionality was announced for C# 6. It is now possible to write try { … } catch (MyException e) when (myfilter(e)) { … } You can download the preview of Visual Studio 2015 now to check this out, or wait for the official release. 回答2: There's no

C# equivalent to VB.NET's Catch…When

£可爱£侵袭症+ 提交于 2019-12-30 06:00:11
问题 In VB.NET I often Catch…When : Try … Catch e As ArgumentNullException When e.ParamName.ToUpper() = "SAMPLES" … End Try Is there a C# equivalent to Catch…When ? I don't want to resort to using an if statement inside a catch if possible. 回答1: This functionality was announced for C# 6. It is now possible to write try { … } catch (MyException e) when (myfilter(e)) { … } You can download the preview of Visual Studio 2015 now to check this out, or wait for the official release. 回答2: There's no

Learning Exception Handling Patterns [closed]

微笑、不失礼 提交于 2019-12-30 05:07:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . One thing that has always mystified me in programming is the use of appropriate exception handling. Code Complete points out that often times 90% of code is focused on handling exceptions. While I know the basics of implementing a basic exception, I have not found good general

Handle Arbitrary Exception, Print Default Exception Message

*爱你&永不变心* 提交于 2019-12-30 03:47:08
问题 I have a program, a part of which executes a loop. During the execution of this loop, there are exceptions. Obviously, I would like my program to run without errors, but for the sake of progress, I would like the program to execute over the entire input and not stop when an exception is thrown. The easiest way to do this would be by implementing an except block. However, when I do this, it except s all exceptions and continues with the program and I never get to see the exception message,

Log shows Error object: {“isTrusted”:true} instead of actual error data

怎甘沉沦 提交于 2019-12-30 03:43:10
问题 I have an event handler that looks like this: window.addEventListener('error', function (e) { SendLogErrorToServer('Error: ' + e.message + 'Error object: ' + JSON.stringify(e) + 'Script: ' + e.filename + 'Line: ' + e.lineno + 'Col: ' + e.colno + 'Nav: ' + window.navigator.userAgent)); }, false); The problem is that what I receive looks like this: Error: Script error.Error object: {"isTrusted":true} Script: Line: 0 Col: 0 Nav: Mozilla/5.0 As you can see, no line number or error message that's

Using UncaughtExceptionHandler effectively

二次信任 提交于 2019-12-30 03:37:13
问题 I got to know about this Java 1.5 capability recently and I developed a sample code to use this. My objective is to restart the thread when it gets dead due to an uncaught exception. public class ThreadManager { public static void main(String[] args) throws InterruptedException { startThread(); } public static void startThread(){ FileReaderThread reader = new FileReaderThread("C:\\Test.txt"); Thread thread = new Thread(reader); thread.setUncaughtExceptionHandler(new CustomExceptionHandler());

R : catching errors in `nls`

喜夏-厌秋 提交于 2019-12-30 03:26:08
问题 I'm fitting some exponential data using nls . The code I'm using is: fit <- nls(y ~ expFit(times, A, tau, C), start = c(A=100, tau=-3, C=0)) expFit is defined as expFit <- function(t, A, tau, C) { expFit <- A*(exp(-t/tau))+C } This works well for most of my data, for which the starting parameters provided (100, -3 and 0) work well. Sometimes, though, I have data that doesn't go well with those parameters and I get errors from nls (e.g. "singular gradient" or things like that). How do I "catch

Scala-way to handle conditions in for-comprehensions?

我与影子孤独终老i 提交于 2019-12-30 03:25:18
问题 I am trying to create a neat construction with for-comprehension for business logic built on futures. Here is a sample which contains a working example based on Exception handling: (for { // find the user by id, findUser(id) returns Future[Option[User]] userOpt <- userDao.findUser(userId) _ = if (!userOpt.isDefined) throw new EntityNotFoundException(classOf[User], userId) user = userOpt.get // authenticate it, authenticate(user) returns Future[AuthResult] authResult <- userDao.authenticate

Python exception handling in list comprehension

末鹿安然 提交于 2019-12-30 03:15:11
问题 I have a Python function called plot_pdf(f) that might throw an error. I use a list comprehension to iterate over a list of files on this function: [plot_pdf(f) for f in file_list] I want to use try-except block to skip any possible errors during the iteration loop and continue with the next file. So is the following code correct way to do the exception handling in Python list comprehension? try: [plot_pdf(f) for f in file_list] # using list comprehensions except: print ("Exception: ", sys

Re-assign exception from within a python __exit__ block

浪子不回头ぞ 提交于 2019-12-30 02:00:30
问题 From within an __exit__ block in a custom cursor class I want to catch an exception so I can in turn throw a more specific exception. What is the proper way to do this? class Cursor: def __enter__(self): ... def __exit__(self, ex_type, ex_val, tb): if ex_type == VagueThirdPartyError: # get new more specific error based on error code in ex_val and # return that one in its place. return False # ? else: return False Raising the specific exception within the __exit__ block seems like a hack, but