Best Practice for MySQL connection

Well that what I’m doing - if there is no connection the exception fires. But when I try to programmatically reopen the connection, the window freezes.