Exception behavior in general
20/01/2018 12:08
Hello, i'm trying to learn Java from the book head-first java. I'mcurrently learning about exceptions. My question is this: when I try/catchan exception, the program hangs instead of exiting, what am I doing wrong?here is the code I'm using:

import javax.sound.midi.*;
public class MusicTest1{ public String play(){ try{ Sequencer sequencer = MidiSystem.getSequencer(); return(We got a Sequencer!); } catch(MidiUnavailableException ex){ return(Bummer!); } } public static void main(String[] args){ MusicTest1 mt = new MusicTest1(); System.out.println(mt.play()); }}
The program doesn't actually do much of anything, other then let you knowif you got a Sequencer. It's just meant to explain Exceptions. When I runit I get a sequencer, but then the program hangs. I'm lost, as I can't seeany reason for it to do so. Any help would be greatly appreciated.


-sam union

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
20/01/2018 12:08 - On Sat, 03 Jul 2004 13:07:09 -0500, sam union <sam.union@cox.net>wrote or quoted :

You have likely started another thread that is handling the sequencer.

Look for some sort of shutdown method.


That thread is still alive.



Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
20/01/2018 12:08 -
Sorry, I should have mentioned that. Heres how it goes:

shell> java MusicTest1We Got a Sequencer!
And the cursor Blinks. And Blinks. And Blinks. :) To get out I have to hitctrl-c.


Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
20/01/2018 12:08 - On Sat, 03 Jul 2004 12:23:31 -0500, sam union <sam.union@cox.net>wrote or quoted :

I presume you are firing this off from the command line with
java.exe MusicTest1
Is there nothing on the console?

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
20/01/2018 12:08 - I wasn't worried about it as much as curious. Thanks for the help,System.exit(0); worked.


Thanks again,-sam

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
20/01/2018 12:08 - I'm not sure I understand what you're saying, as I don't really understandthreads at all. But following your advice I looked up the Sequencerinterface in the Java API, and it inherits a close() method from theMidiDevice class. Close() Closes the device, indicating that the deviceshould now release any system resources it is using. I tried this and,still no luck.
On a slight tangent, it seems like you are saying that A new threadcan be opened without my explicitly asking it to be. Is that true? Also,are threads an object? or are they implemented in some other way? I'mprobably making myself sound like a fool, if so, just let me know!
Thanks for your help,sam

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
20/01/2018 12:08 - On Sat, 03 Jul 2004 13:53:54 -0500, sam union <sam.union@cox.net>wrote or quoted :

A method can do whatever it wants without telling you, includingspawning a new thread. A Thread is an object among other things.


See http://mindprod.com/jgloss/thread.html
I would not worry about this. Just make your main method quit even ifthere are still some threads running by using System.exit( 0 );

Source is Usenet: comp.lang.java.help
Sign in to add a comment

eDiscover
Helpforce eDiscover provides technical articles updated each dayHelpforce eDiscover RSS feed contains the latest technical articles in RSS
Click the logo to go back to the main page
Search eDiscover
  
Categories

Click an icon to go to that category

Helpforce eDiscover contains articles about Microsoft Windows Helpforce eDiscover contains articles about Apple products and MacOS Helpforce eDiscover contains articles about Linux and POSIX operating systems Helpforce eDiscover contains articles about Helpforce Helpforce has a large variety of technical information and articles for you to read Helpforce eDiscover contains articles about databases, MYSQL, SQL Server Oracle Helpforce eDiscover contains articles about Java, JVM and the JRE Helpforce eDiscover contains articles about the QNX operating system Helpforce eDiscover contains articles about Oracle Solaris and Open Solaris Helpforce eDiscover contains articles about RISC OS, Acorn and the BBC Micro Helpforce eDiscover contains articles about Amiga and AmigaOS

Type your comment into the box below