digitalmars.D - Catching serveral types of exceptions.
- =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= (42/42) May 26 2004 I was just trying this piece of code and I see it isn't supported by the...
I was just trying this piece of code and I see it isn't supported by the DMD compiler: try { // ... } catch (ConvError, ConvOverflowError) { statusBar.text = "Please, type number between 1 and 10."; } If I remember correctly Python can do this in it's try/except construct. In this particular case both exceptions are thrown by because the user enter an invalid number in a text field, the error handling code for both exceptions is just to inform the user. Another case where this is handy is in GUI code where it's common to just do: try { // ... } catch (Exception) { MessageBox.Show("The period couldn't be saved to database."); } something like this instead: catch (OleDbException, OleDbError) { MessageBox.Show("The event couldn't be saved to database."); } Is it possible to add this feature to the language? It isn't too late? :) Thanks -- Julio César Carrascal Urquijo http://jcesar.f2o.org/ -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS$ d- s+:+ a-- C++> ULS++ P++ L+> !E W+++ N+ o? K? w++> O--- M V? PS+ PE Y+ PGP t+ 5- X+++ R- tv+(++) b++> DI! D++> G e+> h-- r- y+ ------END GEEK CODE BLOCK------
May 26 2004