Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Uwe Wienkop
Prog2-SS2020-Wienkop
Commits
4c5cfaed
Commit
4c5cfaed
authored
May 26, 2020
by
Uwe Wienkop
Browse files
2020-05-26b
parent
90e4489d
Changes
9
Hide whitespace changes
Inline
Side-by-side
.vs/prog2-ss2020-wienkop/v16/.suo
View file @
4c5cfaed
No preview for this file type
05Exceptions2/Program.cs
View file @
4c5cfaed
...
...
@@ -8,12 +8,16 @@ namespace _06Exceptions
{
class
Program
{
class
Quadrierfehler
:
ArgumentOutOfRange
Exception
class
MyAppExceptions
:
Exception
{
public
Quadrierfehler
(
string
Fehlertext
)
:
base
(
Fehlertext
)
{
}
public
MyAppExceptions
(
string
Fehlertext
=
""
)
:
base
(
Fehlertext
)
{
}
}
class
MyInputExceptions
:
MyAppExceptions
{
}
static
int
funktion2
(
int
x
)
{
//MyAppExceptions ex = new MyAppExceptions("Fehlertest");
//throw ex;
if
(
x
<
0
)
throw
new
ArgumentOutOfRangeException
(
"Fehler in funktion2"
);
return
x
*
x
*
x
;
...
...
@@ -22,7 +26,7 @@ namespace _06Exceptions
{
funktion2
(
x
);
if
(
x
<
0
)
throw
new
Quadrierfehler
(
"So nicht!!!"
);
throw
new
MyAppExceptions
(
"So nicht!!!"
);
if
(
x
==
0
)
throw
new
ArgumentOutOfRangeException
(
"Argument darf nicht null sein"
);
return
x
*
x
;
...
...
@@ -35,7 +39,7 @@ namespace _06Exceptions
funktion
(-
3
);
funktion
(-
2
);
}
catch
(
Quadrierfehler
q
)
catch
(
MyAppExceptions
q
)
{
Console
.
WriteLine
(
"Quadrierfehler"
);
}
...
...
06 UebgDiExceptions/Program.cs
View file @
4c5cfaed
...
...
@@ -9,26 +9,71 @@ namespace _06_UebgDiExceptions
// und Funktion2 ruft Funktion3. Setzen Sie hinter die catches jeweils ein finally
// Schreiben Sie entsprechende catch-Methoden, werfen Sie den Fehler weiter
// und stellen Sie sicher, dass das Programm unter keinen Umständen mit einer Exception beendet wird!
class
MyAppExceptions
:
Exception
{
public
int
fehlerwert
;
public
MyAppExceptions
(
string
Fehlertext
,
int
fehlerwert
)
:
base
(
Fehlertext
)
{
this
.
fehlerwert
=
fehlerwert
;
}
}
class
Program
{
static
void
Funktion
2
()
static
void
Funktion
1
()
{
Console
.
WriteLine
(
"Funktion1"
);
try
{
Funktion2
();
Console
.
WriteLine
(
"Letzte Anweisung des try-Blocks von Funktion 1"
);
}
catch
(
ArgumentException
)
{
}
finally
{
Console
.
WriteLine
(
"Finally von Funktion 1"
);
}
Console
.
WriteLine
(
"Ende von Funktion1"
);
}
static
void
Funktion2
()
{
Console
.
WriteLine
(
"Funktion2"
);
try
{
Funktion3
();
Console
.
WriteLine
(
"Letzte Anweisung des try-Blocks von Funktion 2"
);
}
catch
()
catch
(
MyAppExceptions
e
)
{
Console
.
WriteLine
(
$"catch in Funktion 2:
{
e
.
Message
}
,
{
e
.
fehlerwert
}
"
);
throw
;
}
finally
{
Console
.
WriteLine
(
"Finally von Funktion 2"
);
}
Console
.
WriteLine
(
"Ende von Funktion2"
);
}
static
void
Funktion3
()
{
Console
.
WriteLine
(
"Funktion3"
);
int
x
=
2
;
if
(
1
<
x
)
throw
new
MyAppExceptions
(
"Fehler in Funktion3"
,
4711
);
Console
.
WriteLine
(
"Ende von Funktion3"
);
}
static
int
errno
=
0
;
static
void
Funktion3b
()
{
int
x
=
0
;
errno
=
9999
;
int
y
=
3
/
x
;
}
static
void
Main
(
string
[]
args
)
{
Console
.
WriteLine
(
"Hello World!"
);
Funktion1
(
);
}
}
}
06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.dll
View file @
4c5cfaed
No preview for this file type
06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb
View file @
4c5cfaed
No preview for this file type
06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csproj.FileListAbsolute.txt
View file @
4c5cfaed
...
...
@@ -10,3 +10,4 @@ C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.genruntimeconfig.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.csprojAssemblyReference.cache
06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csprojAssemblyReference.cache
0 → 100644
View file @
4c5cfaed
File added
06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.dll
View file @
4c5cfaed
No preview for this file type
06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb
View file @
4c5cfaed
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment