Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
BrownZeus

Database successes and fails, java

Recommended Posts

Posted · Original PosterOP

Hey guys,

 

I'm having a case of "I don't know how to query my google search to find the answers I want"

 

So if I can be pointed in the right direction that would be great.

 

I have a java app that I'm writing that reads and writes to a MariaDB database.

How do I go about detecting the different exeptions that are thrown? For example, if the connection to the DB fails, obviously an SQLException is thrown, but a specific type, also obvious. So how do I read the exception so I can provide the proper handling for it?

 

TIA

Link to post
Share on other sites

I'm not sure I understand exactly the problem you are having.

 

If your problem is that there might come more than one type of exception from within a try statement, just add several catch clauses

try{
 <whatever comes in> 
}
catch (ExceptionTypeOne e){
  <handle exception>
}
catch (ExceptionTypeTwo e){
 <handle exception> 
}

If your problem is that you want to differenciate according to the content of the exception, you should look into the 'e' object so you can try and find whatever you are looking for


The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to post
Share on other sites
Posted · Original PosterOP
9 minutes ago, espurritado said:

I'm not sure I understand exactly the problem you are having.

 

If your problem is that there might come more than one type of exception from within a try statement, just add several catch clauses


try{
 <whatever comes in> 
}
catch (ExceptionTypeOne e){
  <handle exception>
}
catch (ExceptionTypeTwo e){
 <handle exception> 
}

If your problem is that you want to differenciate according to the content of the exception, you should look into the 'e' object so you can try and find whatever you are looking for

Yes, basically I wanna read into what the content of exception is and handle according to the different errors. 

 

So how do I look into the e object and get the content of the exception?

Link to post
Share on other sites
46 minutes ago, BrownZeus said:

Yes, basically I wanna read into what the content of exception is and handle according to the different errors. 

 

So how do I look into the e object and get the content of the exception?

 

find the oracle documentation for the base Exception object https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Exception.html
and see what the doc says about it, what fields it has, expected usage, etc.

 

Another way is just see for yourself. Make a small dummy project, throw an exception while debugging, and use a breakpoint to pause execution in your catch block so you can analyze the exception object you caught.


Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Newegg

×