You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by "USHAKOV, Sergey" <s....@chemitech.ru> on 2011/04/23 08:18:53 UTC

Exception handling in a matcher static initializer block

Hi all,

what would be the right behavior for a matcher when an exception happens in 
its static initializer block?

Wrap the exception into a RuntimeException and re-throw? Do a 
'e.printStackTrace()'? Something else?

Thanks and best regards,
Sergey 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


Re: Exception handling in a matcher static initializer block

Posted by "USHAKOV, Sergey" <s....@chemitech.ru>.
Ok, thanks. I'll go ahead this way... :)

Regards,
Sergey



----- Original Message ----- 
From: "Norman Maurer" <no...@googlemail.com>
To: "James Users List" <se...@james.apache.org>
Sent: Saturday, April 23, 2011 5:25 PM
Subject: Re: Exception handling in a matcher static initializer block


Ah ok.. Yeah RuntimeException should work... :)

Bye,
Norman


2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
> Well, I mean something like this:
>
> import java.io.ByteArrayInputStream;
> import javax.xml.transform.Templates;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.stream.StreamSource;
>
> public class XXX extends GenericMatcher {
> protected static Templates xsltTemplate;
> private static final String XSLT_EXTRACT_TEXT = "...";
>
> static {
> TransformerFactory factory = TransformerFactory.newInstance ();
> StreamSource xsltSource =
> new StreamSource (new ByteArrayInputStream (XSLT_EXTRACT_TEXT.getBytes
> ()));
> try {
> xsltTemplate = factory.newTemplates (xsltSource);
> }
> catch (TransformerConfigurationException e) {
> throw new RuntimeException ("Error creating compiled XSLT template", e);
> }
> }
> ...
> }
>
> static {...} allows to re-use the 'xsltTemplate' object that was created
> once for all instances of the same matcher.
>
> Regards,
> Sergey
>
>
>
> ----- Original Message ----- From: "Norman Maurer"
> <no...@googlemail.com>
> To: "James Users List" <se...@james.apache.org>
> Sent: Saturday, April 23, 2011 5:06 PM
> Subject: Re: Exception handling in a matcher static initializer block
>
>
>> Which static method you are refer to ?
>>
>> Bye,
>> Norman
>>
>>
>> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>>>
>>> Well, I agree it would be the right approach in any other context.
>>> Unfortunately the compiler does not approve it in a static initializer
>>> and
>>> complains on unhandled exception. It has no objections against a
>>> RuntimeException (the one that is not expected to be caught) though.
>>>
>>> Will JAMES treat a RuntimeException in the right way?
>>>
>>> Regards,
>>> Sergey
>>>
>>>
>>> ----- Original Message ----- From: "Norman Maurer"
>>> <no...@googlemail.com>
>>> To: "James Users List" <se...@james.apache.org>
>>> Sent: Saturday, April 23, 2011 4:45 PM
>>> Subject: Re: Exception handling in a matcher static initializer block
>>>
>>>
>>>> You should just throw a MessagingException in this case. This will
>>>> make sure JAMES will not start at all.
>>>>
>>>>
>>>> Bye,
>>>> Norman
>>>>
>>>> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>>>>>
>>>>> Hi all,
>>>>>
>>>>> what would be the right behavior for a matcher when an exception
>>>>> happens
>>>>> in
>>>>> its static initializer block?
>>>>>
>>>>> Wrap the exception into a RuntimeException and re-throw? Do a
>>>>> 'e.printStackTrace()'? Something else?
>>>>>
>>>>> Thanks and best regards,
>>>>> Sergey
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


Re: Exception handling in a matcher static initializer block

Posted by Norman Maurer <no...@googlemail.com>.
Ah ok.. Yeah RuntimeException should work... :)

Bye,
Norman


2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
> Well, I mean something like this:
>
> import java.io.ByteArrayInputStream;
> import javax.xml.transform.Templates;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.stream.StreamSource;
>
> public class XXX extends GenericMatcher {
>  protected static Templates xsltTemplate;
>  private static final String XSLT_EXTRACT_TEXT = "...";
>
>  static {
>   TransformerFactory factory = TransformerFactory.newInstance ();
>   StreamSource xsltSource =
>     new StreamSource (new ByteArrayInputStream (XSLT_EXTRACT_TEXT.getBytes
> ()));
>   try {
>     xsltTemplate = factory.newTemplates (xsltSource);
>   }
>   catch (TransformerConfigurationException e) {
>     throw new RuntimeException ("Error creating compiled XSLT template", e);
>   }
>  }
> ...
> }
>
> static {...} allows to re-use the 'xsltTemplate' object that was created
> once for all instances of the same matcher.
>
> Regards,
> Sergey
>
>
>
> ----- Original Message ----- From: "Norman Maurer"
> <no...@googlemail.com>
> To: "James Users List" <se...@james.apache.org>
> Sent: Saturday, April 23, 2011 5:06 PM
> Subject: Re: Exception handling in a matcher static initializer block
>
>
>> Which static method you are refer to ?
>>
>> Bye,
>> Norman
>>
>>
>> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>>>
>>> Well, I agree it would be the right approach in any other context.
>>> Unfortunately the compiler does not approve it in a static initializer
>>> and
>>> complains on unhandled exception. It has no objections against a
>>> RuntimeException (the one that is not expected to be caught) though.
>>>
>>> Will JAMES treat a RuntimeException in the right way?
>>>
>>> Regards,
>>> Sergey
>>>
>>>
>>> ----- Original Message ----- From: "Norman Maurer"
>>> <no...@googlemail.com>
>>> To: "James Users List" <se...@james.apache.org>
>>> Sent: Saturday, April 23, 2011 4:45 PM
>>> Subject: Re: Exception handling in a matcher static initializer block
>>>
>>>
>>>> You should just throw a MessagingException in this case. This will
>>>> make sure JAMES will not start at all.
>>>>
>>>>
>>>> Bye,
>>>> Norman
>>>>
>>>> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>>>>>
>>>>> Hi all,
>>>>>
>>>>> what would be the right behavior for a matcher when an exception
>>>>> happens
>>>>> in
>>>>> its static initializer block?
>>>>>
>>>>> Wrap the exception into a RuntimeException and re-throw? Do a
>>>>> 'e.printStackTrace()'? Something else?
>>>>>
>>>>> Thanks and best regards,
>>>>> Sergey
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


Re: Exception handling in a matcher static initializer block

Posted by "USHAKOV, Sergey" <s....@chemitech.ru>.
Well, I mean something like this:

import java.io.ByteArrayInputStream;
import javax.xml.transform.Templates;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;

public class XXX extends GenericMatcher {
  protected static Templates xsltTemplate;
  private static final String XSLT_EXTRACT_TEXT = "...";

  static {
    TransformerFactory factory = TransformerFactory.newInstance ();
    StreamSource xsltSource =
      new StreamSource (new ByteArrayInputStream (XSLT_EXTRACT_TEXT.getBytes 
()));
    try {
      xsltTemplate = factory.newTemplates (xsltSource);
    }
    catch (TransformerConfigurationException e) {
      throw new RuntimeException ("Error creating compiled XSLT template", 
e);
    }
  }
...
}

static {...} allows to re-use the 'xsltTemplate' object that was created 
once for all instances of the same matcher.

Regards,
Sergey



----- Original Message ----- 
From: "Norman Maurer" <no...@googlemail.com>
To: "James Users List" <se...@james.apache.org>
Sent: Saturday, April 23, 2011 5:06 PM
Subject: Re: Exception handling in a matcher static initializer block


> Which static method you are refer to ?
>
> Bye,
> Norman
>
>
> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>> Well, I agree it would be the right approach in any other context.
>> Unfortunately the compiler does not approve it in a static initializer 
>> and
>> complains on unhandled exception. It has no objections against a
>> RuntimeException (the one that is not expected to be caught) though.
>>
>> Will JAMES treat a RuntimeException in the right way?
>>
>> Regards,
>> Sergey
>>
>>
>> ----- Original Message ----- From: "Norman Maurer"
>> <no...@googlemail.com>
>> To: "James Users List" <se...@james.apache.org>
>> Sent: Saturday, April 23, 2011 4:45 PM
>> Subject: Re: Exception handling in a matcher static initializer block
>>
>>
>>> You should just throw a MessagingException in this case. This will
>>> make sure JAMES will not start at all.
>>>
>>>
>>> Bye,
>>> Norman
>>>
>>> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>>>>
>>>> Hi all,
>>>>
>>>> what would be the right behavior for a matcher when an exception 
>>>> happens
>>>> in
>>>> its static initializer block?
>>>>
>>>> Wrap the exception into a RuntimeException and re-throw? Do a
>>>> 'e.printStackTrace()'? Something else?
>>>>
>>>> Thanks and best regards,
>>>> Sergey
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


Re: Exception handling in a matcher static initializer block

Posted by Norman Maurer <no...@googlemail.com>.
Which static method you are refer to ?

Bye,
Norman


2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
> Well, I agree it would be the right approach in any other context.
> Unfortunately the compiler does not approve it in a static initializer and
> complains on unhandled exception. It has no objections against a
> RuntimeException (the one that is not expected to be caught) though.
>
> Will JAMES treat a RuntimeException in the right way?
>
> Regards,
> Sergey
>
>
> ----- Original Message ----- From: "Norman Maurer"
> <no...@googlemail.com>
> To: "James Users List" <se...@james.apache.org>
> Sent: Saturday, April 23, 2011 4:45 PM
> Subject: Re: Exception handling in a matcher static initializer block
>
>
>> You should just throw a MessagingException in this case. This will
>> make sure JAMES will not start at all.
>>
>>
>> Bye,
>> Norman
>>
>> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>>>
>>> Hi all,
>>>
>>> what would be the right behavior for a matcher when an exception happens
>>> in
>>> its static initializer block?
>>>
>>> Wrap the exception into a RuntimeException and re-throw? Do a
>>> 'e.printStackTrace()'? Something else?
>>>
>>> Thanks and best regards,
>>> Sergey
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-user-help@james.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


Re: Exception handling in a matcher static initializer block

Posted by "USHAKOV, Sergey" <s....@chemitech.ru>.
Well, I agree it would be the right approach in any other context. 
Unfortunately the compiler does not approve it in a static initializer and 
complains on unhandled exception. It has no objections against a 
RuntimeException (the one that is not expected to be caught) though.

Will JAMES treat a RuntimeException in the right way?

Regards,
Sergey


----- Original Message ----- 
From: "Norman Maurer" <no...@googlemail.com>
To: "James Users List" <se...@james.apache.org>
Sent: Saturday, April 23, 2011 4:45 PM
Subject: Re: Exception handling in a matcher static initializer block


> You should just throw a MessagingException in this case. This will
> make sure JAMES will not start at all.
>
>
> Bye,
> Norman
>
> 2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
>> Hi all,
>>
>> what would be the right behavior for a matcher when an exception happens 
>> in
>> its static initializer block?
>>
>> Wrap the exception into a RuntimeException and re-throw? Do a
>> 'e.printStackTrace()'? Something else?
>>
>> Thanks and best regards,
>> Sergey
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-user-help@james.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org


Re: Exception handling in a matcher static initializer block

Posted by Norman Maurer <no...@googlemail.com>.
You should just throw a MessagingException in this case. This will
make sure JAMES will not start at all.


Bye,
Norman

2011/4/23 USHAKOV, Sergey <s....@chemitech.ru>:
> Hi all,
>
> what would be the right behavior for a matcher when an exception happens in
> its static initializer block?
>
> Wrap the exception into a RuntimeException and re-throw? Do a
> 'e.printStackTrace()'? Something else?
>
> Thanks and best regards,
> Sergey
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org