Defining a static variable that throws an Exception

H

harald ebert

Hello,

I tried to define and initialize a static variable with an object
whoes constructor throws an Exception.

public class MyClass1 {

private static DataFlavor flavor = new DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + ";class=MyClass2");

}

The DataFlavor class throws an Exception.

Is it possible to do what i want to do?
How can I catch the Exception?

Thanks for your help

Harald Ebert
 
R

Rogan Dawes

harald said:
Hello,

I tried to define and initialize a static variable with an object
whoes constructor throws an Exception.

public class MyClass1 {

private static DataFlavor flavor = new DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + ";class=MyClass2");

}

The DataFlavor class throws an Exception.

Is it possible to do what i want to do?
How can I catch the Exception?

Thanks for your help

Harald Ebert

Initialise it in a static block.

See http://www.developer.com/java/other/article.php/2238491 for an example.

Rogan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top