exception

If RuntimeException is thrown, can it be caught as an Exception?

試著忘記壹切 提交于 2019-12-23 16:04:52
问题 If I have a try block that throws a RuntimException subclass, can a subsequent catch block catches it as an Exception ? Specifically: public class MyAppException extends RuntimeException { // .... } // In some other part of the code: try { // Executing this results with doSomething() throwing a MyAppException. int x = doSomething(); } catch(Exception exc) { // Does the thrown MyAppException get caught here? } My thinking is yes , because a RuntimeException extends Exception . However I have

UnauthorizedAccessException when using Directory.GetFiles

假如想象 提交于 2019-12-23 16:03:09
问题 In the application I am writing, the user has the ability to add some folder to search for some files recursively. The problem is the files he wants to add to the app might be stored in the base drive like K:. So if he add this drive directly, I get an exception. Or if he adds C:\, then I get UnauthorizedAccessException where it says: Access to the path 'C:\System Volume Information' is denied. How can I just scan where I can scan? And give the ability to scan another non-system drive fully

UnknownHostException while formatting HDFS

不羁岁月 提交于 2019-12-23 15:16:46
问题 I have installed CDH4 on CentOS 6.3 64-bit in Pseudo Distributed mode using the following instructions. Everything is set to localhost in the Hadoop configuration files. But, still when I format the name node the below exception appears. When I add an 192.168.1.101 CentOSHost entry to the /etc/hosts file the exception goes away and I am able to run format/start HDFS and run MR jobs. I want to run MR jobs even when I am not connected to the network without adding an entry to the /etc/hosts

When to throw IllegalStateException vs IllegalArgumentException?

假如想象 提交于 2019-12-23 15:12:23
问题 Let's start with the Javadocs: IllegalStateException Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation. IllegalArgumentException Thrown to indicate that a method has been passed an illegal or inappropriate argument. The problem with the above is that they are very black and white. Consider a use case where a method is parsing a file provided by the

How to catch ParamConverter exceptions in Symfony2?

ぃ、小莉子 提交于 2019-12-23 14:21:28
问题 Here is the exception I got: No result was found for query although at least one row was expected. I am basically getting that exception when a user id is not found in database. Here is what my route looks like: localhost/../user/18 and the code in my controller: public function showAction(User $user){ // .. } I know I can use the kernel event exception to handle this, but is there an easier way to catch an exception generated by the ParamConverter? 回答1: In some cases it's useful to throw

Core dump equivalent for the Rails exception

梦想与她 提交于 2019-12-23 14:02:48
问题 So I got an exception log from my application. I have a call stack, request parameters and all other usual stuff in that log. This is a rare exception and info from the log doesn't contain all details I need to resolve / duplicate the problem. I wonder if there is some way (gem?) to get full dump of Rails application state in case of an exception. Including all instance and local variables values from a controller methods. I guess that dump of whole Ruby object space might take even a minute

Java Programming Error: java.util.ConcurrentModificationException

假装没事ソ 提交于 2019-12-23 13:09:14
问题 I'm writing a program as part of tutorial for a beginner Java student. I have the following method and whenever I run it, it gives me the following exception: java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at Warehouse.receive(Warehouse.java:48) at MainClass.main(MainClass.java:13) Here's the method itself, within the class Warehouse: public void receive(MusicMedia

Android Visualizer (Audio Effects) runtime exception on Ice Cream Sandwich

自古美人都是妖i 提交于 2019-12-23 13:06:33
问题 In the sample AudioFxDemo.java, provided with the SDK, I get a java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -4 when trying to create the android.media.audiofx.Visualizer mVisualizer = new Visualizer(mMediaPlayer.getAudioSessionId()); (AudioFxDemo.java:173). As far as I can see, the error originates in the native code, (lines 266 ff.) An error also happens when trying to create the android.media.audiofx.Equalizer: mEqualizer = new Equalizer(0, mMediaPlayer

How to Catch an exception in a using block with .NET 2.0?

回眸只為那壹抹淺笑 提交于 2019-12-23 13:03:12
问题 I'm trying to leverage the using block more and more these days when I have an object that implements IDisposable but one thing I have not figured out is how to catch an exception as I would in a normal try/catch/finally ... any code samples to point me in the right direction? Edit: The question was modified after reading through the replies. It was "How to Throw an exception in a using block with .NET 2.0?" but I was actually looking for a way to catch these exceptions inside a using block.

NUnit Unit Test has “ExpectedException” but still failing on exception

落花浮王杯 提交于 2019-12-23 12:54:38
问题 I have a unit test that is failing because a System.ArgumentException is being thrown, even though I am expecting it and it's deliberate behaviour - what have I missed? [Test] [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Seconds from midnight cannot be more than 86400 in 010100712386401000000012")] public void TestParsingCustomReferenceWithInValidSecondsFromMidnight() { // I am expecting this method to throw an ArgumentException: CustomReference.Parse(