Re: noob question about try/catch

2013-04-27 Thread Neale Swinnerton
On Fri, Apr 26, 2013 at 5:55 PM, Michael Gardner

> I believe Clojure is wrapping the java.sql.SQLException in a
> java.lang.RuntimeException because of reasons[1][2], so you'd need to catch
> java.lang.RuntimeException and examine the exception's cause property to
> get the "real" exception.
>
>
Agree with Michael that the SQLException is being wrapped in a
RuntimeException and that's why it's escaping your catch block, so you'll
need to tweak your logic for that.

Having said that you might be interested to know that the mysql jdbc driver
has a config option to help with this specific exception with 'zero'
timestamps.[1]

You probably want to add

zeroDateTimeBehavior=convertToNull
to your JDBC URL

[1]
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: noob question about try/catch

2013-04-26 Thread Sean Corfield
What does your code look like that queries MySQL? The above code
writes to MongoDB which is not going to throw SQLException anyway.

On Fri, Apr 26, 2013 at 8:01 AM, larry google groups
 wrote:
>
> I wrote a simple app that gets my data out of an old mysql database and puts
> it into mongodb. I have this function:
>
> (defn add-this-record-to-mongo [db record item-type]
>   (println (str (:user db)))
>   (println (str item-type))
>   (try
> (let [record (assoc record :item-type item-type)
>   record (assoc record :community (:user db))
>   item-name (str (:community record) "-" (:item-type record) "-"
> (:id record))
>   record (assoc record :item-name item-name)]
>   (mongo/persist-document-to-database record))
> (catch java.sql.SQLException e (println (apply str e)
>
> Right now, when I run this app, it grabs the first 147,879 records and then
> dies with this exception:
>
> java.lang.RuntimeException: java.sql.SQLException: Cannot convert value
> '-00-00 00:00:00' from column 6 to TIMESTAMP.
>
> I thought I had written the try/catch blog so that this exception would be
> logged, but otherwise ignored.
>
> Instead, this exception stops my app cold -- the app stops.
>
> How do I get the app to ignore these exceptions?
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: noob question about try/catch

2013-04-26 Thread Michael Gardner
On Apr 26, 2013, at 11:55 , Michael Gardner  wrote:

> I believe Clojure is wrapping the java.sql.SQLException in a 
> java.lang.RuntimeException because of reasons[1][2], so you'd need to catch 
> java.lang.RuntimeException and examine the exception's cause property to get 
> the "real" exception.
> 
> [1] http://dev.clojure.org/jira/browse/CLJ-855
> [2] https://groups.google.com/d/msg/clojure/I5l1YHVMgkI/nt8t9aHNVEYJ

…though I just noticed that JIRA issue was closed in 1.3, so unless you're 
still on 1.3 it doesn't actually explain why you're getting wrapped exceptions.

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: noob question about try/catch

2013-04-26 Thread Michael Gardner
On Apr 26, 2013, at 10:01 , larry google groups  
wrote:

> java.lang.RuntimeException: java.sql.SQLException: Cannot convert value 
> '-00-00 00:00:00' from column 6 to TIMESTAMP.

I believe Clojure is wrapping the java.sql.SQLException in a 
java.lang.RuntimeException because of reasons[1][2], so you'd need to catch 
java.lang.RuntimeException and examine the exception's cause property to get 
the "real" exception.

[1] http://dev.clojure.org/jira/browse/CLJ-855
[2] https://groups.google.com/d/msg/clojure/I5l1YHVMgkI/nt8t9aHNVEYJ

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: noob question about try/catch

2013-04-26 Thread larry google groups
> See http://clojure.org/special_forms#try , you're still responsible for 
the 
> logic in the catch to ignore the exception.  

But I have caught the exceptions, so why do they kill my app? 

You link to this, which does not answer the question: 

"The exprs are evaluated and, if no exceptions occur, the value of the last 
is returned. If an exception occurs and catch clauses are provided, each is 
examined in turn and the first for which the thrown exception is an 
instance of the named class is considered a matching catch clause. If there 
is a matching catch clause, its exprs are evaluated in a context in which 
name is bound to the thrown exception, and the value of the last is the 
return value of the function. If there is no matching catch clause, the 
exception propagates out of the function. Before returning, normally or 
abnormally, any finally exprs will be evaluated for their side effects."

I catch the exception and log it. And then the exception kills the app? 
Why? 






On Friday, April 26, 2013 11:53:04 AM UTC-4, George Oliver wrote:
>
>
>
> On Friday, April 26, 2013 8:01:45 AM UTC-7, larry google groups wrote:
>>
>>
>> I thought I had written the try/catch blog so that this exception would 
>> be logged, but otherwise ignored. 
>>
>> Instead, this exception stops my app cold -- the app stops. 
>>
>>
>>
> See http://clojure.org/special_forms#try , you're still responsible for 
> the logic in the catch to ignore the exception.  
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: noob question about try/catch

2013-04-26 Thread George Oliver


On Friday, April 26, 2013 8:01:45 AM UTC-7, larry google groups wrote:
>
>
> I thought I had written the try/catch blog so that this exception would be 
> logged, but otherwise ignored. 
>
> Instead, this exception stops my app cold -- the app stops. 
>
>
>
See http://clojure.org/special_forms#try , you're still responsible for the 
logic in the catch to ignore the exception.  

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




noob question about try/catch

2013-04-26 Thread larry google groups

I wrote a simple app that gets my data out of an old mysql database and 
puts it into mongodb. I have this function:

(defn add-this-record-to-mongo [db record item-type]
  (println (str (:user db)))
  (println (str item-type))
  (try 
(let [record (assoc record :item-type item-type)
  record (assoc record :community (:user db))
  item-name (str (:community record) "-" (:item-type record) "-" 
(:id record))
  record (assoc record :item-name item-name)]
  (mongo/persist-document-to-database record))
(catch java.sql.SQLException e (println (apply str e)

Right now, when I run this app, it grabs the first 147,879 records and then 
dies with this exception:

java.lang.RuntimeException: java.sql.SQLException: Cannot convert value 
'-00-00 00:00:00' from column 6 to TIMESTAMP.

I thought I had written the try/catch blog so that this exception would be 
logged, but otherwise ignored. 

Instead, this exception stops my app cold -- the app stops. 

How do I get the app to ignore these exceptions? 

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.