Re: Catching ClassNotFoundException.

2010-12-16 Thread Meikel Brandmeyer
Hi,

Am 16.12.2010 um 04:16 schrieb Nicolas Buduroi:

 So we could always use RT/classForName to detect what classes are
 available. Do you think the extend-type thrown exception can possibly
 be fixed or is it a fundamental limitation?

I think the problem here is „when“ not „where.“ The „extend-type“ exception is 
thrown when the expression is compiled because the compiler tries to resolve 
the class. But the try catch is not in effect at that time: it just gets 
compiled! Using RT/classForName moves the class resolution to the runtime and 
everything works fine.

You could do something like (try (load file/with/extend-type) (catch 
ClassNotFoundException uhOh ...)).

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Catching ClassNotFoundException.

2010-12-16 Thread Nicolas Buduroi
Cool, that explain everything. Thanks

On Dec 16, 4:40 am, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 16.12.2010 um 04:16 schrieb Nicolas Buduroi:

  So we could always use RT/classForName to detect what classes are
  available. Do you think the extend-type thrown exception can possibly
  be fixed or is it a fundamental limitation?

 I think the problem here is „when“ not „where.“ The „extend-type“ exception 
 is thrown when the expression is compiled because the compiler tries to 
 resolve the class. But the try catch is not in effect at that time: it just 
 gets compiled! Using RT/classForName moves the class resolution to the 
 runtime and everything works fine.

 You could do something like (try (load file/with/extend-type) (catch 
 ClassNotFoundException uhOh ...)).

 Sincerely
 Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Catching ClassNotFoundException.

2010-12-15 Thread Nicolas Buduroi
Hi, is there a way of catching ClassNotFoundException? Using
try..catch doesn't work!

Thanks

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Catching ClassNotFoundException.

2010-12-15 Thread Stuart Halloway
Can you post an example?

(try
 (throw (ClassNotFoundException. What makes you say that?))
 (catch ClassNotFoundException e
   (println (.getMessage e


 Hi, is there a way of catching ClassNotFoundException? Using
 try..catch doesn't work!
 
 Thanks
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Catching ClassNotFoundException.

2010-12-15 Thread Nicolas Buduroi
Yeah, while doing more testing it seems to depend from where the
ClassNotFoundException is thrown. What I was trying to do at first is
to call extend-type on a Java class only if it exists. Surrounding
extend-type by a try..catch clause doesn't work here. So I tried to
simply type:

user (try org.postgresql.PGConnection (catch ClassNotFoundException
e :catched))
; Evaluation aborted.

And, as you see, the try..catch didn't work either. But I just found
out that when using Clojure internal classForName method it can be
catched:

user (try (clojure.lang.RT/classForName
org.postgresql.PGConnection ) (catch ClassNotFoundException
e :catched))
:catched

So we could always use RT/classForName to detect what classes are
available. Do you think the extend-type thrown exception can possibly
be fixed or is it a fundamental limitation?

On Dec 15, 9:27 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
 Can you post an example?

 (try
  (throw (ClassNotFoundException. What makes you say that?))
  (catch ClassNotFoundException e
    (println (.getMessage e

  Hi, is there a way of catching ClassNotFoundException? Using
  try..catch doesn't work!

  Thanks

  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with 
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en