exception

How to avoid java.nio.file.AccessDeniedException when using java.nio.file.Files.move()?

自古美人都是妖i 提交于 2021-01-28 07:46:47
问题 My Java program (see below) sometimes crashes with a java.nio.file.AccessDeniedException in a java.nio.File.move() method execution. I could not understand why this exception is thrown and I have no bypass for now. Here is an example of the exception : java.nio.file.AccessDeniedException: C:\PROJECTS\PROJECT0\CHANGES -> C:\PROJECTS\PROJECT0\GEN70\CHANGES at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:95) at sun.nio.fs.WindowsException.rethrowAsIOException

Use of Exception.__init__(self) for user defined exceptions

ε祈祈猫儿з 提交于 2021-01-28 07:00:57
问题 I have been searching online to understand the usage of Exception.__init__(self) for user defined exceptions. For example: I have two user defined exceptions with one Exception.__init__(self) and second without. class MyFirstError(Exception): def __init__(self, result): Exception.__init__(self) self.result = result class MySecondError(Exception): def __init__(self, result): self.result = result def test(): try: raise MyFirstError("__My First Error__") except MyFirstError as exc: return exc

Exception throw in boost::asio::spawn not caught by try catch

≡放荡痞女 提交于 2021-01-28 05:14:31
问题 In this convoluted example, two for loops are started by boost::asio::spawn() asynchronously. The first for loop prints an odd number every 1000us and the second one prints an even number every 1000us. I expect the output to be something like 1 2 3 4 5 6 and then the 'Throw an error' message should be printed to stderr by the call to cerr. However, the exception is actually thrown in loop.run() so it is not caught by the try catch block. Can someone point out how to properly catch the runtime

What am I not getting about [DateTime]::ParseExact()?

爱⌒轻易说出口 提交于 2021-01-28 05:02:05
问题 $timeinfo = "01-‎06‎-2017 ‏‎12:34" $template = "dd-MM-yyyy HH:mm" [DateTime]::ParseExact($timeinfo, $template, $null) results in: Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." At line:3 char:1 + [DateTime]::ParseExact($timeinfo, $template, $null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException I can't tell what is wrong here?

How to swallow … exception with specific reason

帅比萌擦擦* 提交于 2021-01-28 04:13:07
问题 In this method public static void Detach() { try { using (var master = new DataContext(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True")) { master.ExecuteCommand(string.Format("ALTER DATABASE [{0}] SET OFFLINE WITH ROLLBACK IMMEDIATE", DatabaseFile)); master.ExecuteCommand(string.Format("exec sp_detach_db '{0}'", DatabaseFile)); } } catch (Exception e) { ... // add to log } } I can receive exception System.Data.SqlClient.SqlException (0x80131904): The

A simpler way of ignoring specific types of exceptions when awaiting a Task

邮差的信 提交于 2021-01-28 02:24:18
问题 When awaiting a Task I would like to have an easy way to ignore specific types of exceptions, like OperationCanceledException or TimeoutException or whatever. I got the idea of writing an extension method that could wrap my Task , and suppress the Exception type I would give it as argument. So I wrote this one: public static async Task Ignore<TException>(this Task task) where TException : Exception { try { await task; } catch (Exception ex) { if (ex is TException) return; throw; } } I can use

System.BadImageFormatException: Could not load file or assembly- Exception only on hosting server?

只愿长相守 提交于 2021-01-28 01:41:14
问题 I have google this exception and found couple of good links as wel and tried whatever suggested. But still same issue. This exception I am not getting on any of my local server even after deployment on my local server No such issues. But when I move the site to hosting server, first time it loads with no error,but once I press ctrl+f5 I start getting this exception. http://prnt.sc/8x4bm7 This exception I am getting only on remote/hosting server. No such exception in my local. Could not load

From where does the “Contains non-LDH ASCII characters” exception come from?

↘锁芯ラ 提交于 2021-01-27 20:43:25
问题 I develop an application (spring-magnolia) that around this new year (2018) started to throw for me this exception but not for any other colleagues. The exception is right, there is an _ in the a configured host name, so that domain name should be fixed. Still, it was working before and for the other folks it is still working, not throwing this exception. I tried many different things, from tomcat settings to using an older JRE (1.7)... and even switched from Ubuntu to Windows but the

Using multiple exceptions in python

巧了我就是萌 提交于 2021-01-27 14:27:54
问题 Is there a way to use multiple exceptions in python? Like code below: try: #mycode except AttributeError TypeError ValueError: #my exception What I mean is how to use AttributeError TypeError ValueError with each other? 回答1: Use a tuple: try: # mycode except (AttributeError, TypeError, ValueError): # catches any of the three exception types above Quoting the reference try statement documentation: When an exception occurs in the try suite, a search for an exception handler is started. This

std::out_of_range exception is not thrown

折月煮酒 提交于 2021-01-27 11:31:27
问题 // The following code works fine, throwing a std::out_of_range exception: std::vector<double> vd{ 1.5 }; try { int i{ -1 }; double d = vd.at(i); // exception is thrown } catch (std::out_of_range& re) { std::cout << "Exception is " << re.what() << std::endl; // invalid vector subscript } If I access vector elements in a for loop with an invalid index, no std::exception is thrown although I use .at() . Why is the std::out_of_range exception not thrown? // in a for loop, this does not throw the