🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #283

Re: obsluga wyjatkow w C#

#283
From: Marcin Hoppe
Date: Wed, 03 Dec 2003 22:11
42 lines
2165 bytes
Użytkownik "VotA" <vo...@gazeta.pl> napisał w wiadomości
news:bqlktv$n4j$1@inews.gazeta.pl...
> Mam cos takiego:
> int ood = 0;
> try
> {
> ood = System.Int32.Parse(Console.ReadLine());
> }
> catch (System.FormatException)
> {
> Console.WriteLine("Wpisz poprawny zakres! (Tylko liczby naturalne)");
> }
>
> W jaki sposob to przerobic, aby
> ood = System.Int32.Parse(Console.ReadLine());
> wykonywalo sie do czasu wprowadzenia zmiennej typu int?

    A może coś takiego:

    bool flag = false;
    int ood = 0;
    do
    {
        try
        {
            // Jesli wyjatek zostanie rzucony to wlasnie tutaj.
            ood = System.Int32.Parse(Console.ReadLine());
            flag = true;
        }
        catch(System.FormatException)
        {
            Console.WriteLine("Wpisz poprawny zakres! (Tylko liczby
naturalne)");
        }
    }
    while(flag == false);

    Kod jest napisany z palca, więc może nie działać. Choć powinien :).

--
Pozdrawiam!
Marcin
Technical Details
Message-ID: <bqln28$1ll$1@inews.gazeta.pl>
Path: mbox-mo1.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!38.144.126.76.MISMATCH!feed2.newsreader.com!newsreader.com!hermes.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.tpinternet.pl!newsfeed.gazeta.pl!news.gazeta.pl!not-for-mail
References: <bqlktv$n4j$1@inews.gazeta.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!38.144.126.76.MISMATCH!feed2.newsreader.com!newsreader.com!hermes.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.tpinternet.pl!newsfeed.gazeta.pl!news.gazeta.pl!not-for-mail
From: "Marcin Hoppe" <marcin...@spamerzy.won.gazeta.pl>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Re: obsluga wyjatkow w C#
Date: Wed, 3 Dec 2003 23:11:10 +0100
Organization: Portal Gazeta.pl -> http://www.gazeta.pl
Lines: 43
Message-ID: <bqln28$1ll$1@inews.gazeta.pl>
References: <bqlktv$n4j$1@inews.gazeta.pl>
Reply-To: "Marcin Hoppe" <marcin...@spamerzy.won.gazeta.pl>
NNTP-Posting-Host: ww68.neoplus.adsl.tpnet.pl
Mime-Version: 1.0
X-Trace: inews.gazeta.pl 1070489480 1717 80.54.60.68 (3 Dec 2003 22:11:20 GMT)
X-Complaints-To: use...@agora.pl
NNTP-Posting-Date: Wed, 3 Dec 2003 22:11:20 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
X-Priority: 3
X-User: marcin.hoppe
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit