aboutsummaryrefslogtreecommitdiff
path: root/files/tr/web/javascript/reference/statements/throw
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/tr/web/javascript/reference/statements/throw
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/tr/web/javascript/reference/statements/throw')
-rw-r--r--files/tr/web/javascript/reference/statements/throw/index.html201
1 files changed, 201 insertions, 0 deletions
diff --git a/files/tr/web/javascript/reference/statements/throw/index.html b/files/tr/web/javascript/reference/statements/throw/index.html
new file mode 100644
index 0000000000..5ad62b840f
--- /dev/null
+++ b/files/tr/web/javascript/reference/statements/throw/index.html
@@ -0,0 +1,201 @@
+---
+title: throw
+slug: Web/JavaScript/Reference/Statements/throw
+translation_of: Web/JavaScript/Reference/Statements/throw
+---
+<div>{{jsSidebar("Statements")}}</div>
+
+<p><code>Throw </code>ifadesi kullanıcı tanımlı bir istisna atar. Mevcut işlevin yürütülmesi durur (atmadan sonraki ifadeler yürütülmez) ve kontrol, çağrı yığındaki ilk yakalama blokuna geçirilir. Arayanlar arasında yakalama bloğu yoksa, program sonlanır.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/statement-throw.html")}}</div>
+
+<p class="hidden">Bu interaktif örneğin için kaynak bir GitHub deposunda saklanır. Etkileşimli örnek projesine katkıda bulunmak isterseniz, lütfen <a href="/tr/docs/">https://github.com/mdn/interactive-examples</a> klonlayın ve bize bir request isteği gönderin.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox notranslate">throw <em>ifade</em>; </pre>
+
+<dl>
+ <dt><em>ifade</em></dt>
+ <dd>Hata fırlatmak için ifade.</dd>
+</dl>
+
+<h2 id="Açıklama">Açıklama</h2>
+
+<p>Bir hata fırlatmak için <code>throw</code> ifadesini kullanın. Bir hata fırlatırken, ifade hatanın değerini belirtir. Aşağıdakilerin her biri bir hata fırlatır:</p>
+
+<pre class="brush: js notranslate">throw 'Error2'; // String bir ifade ile hata oluşturur.
+throw 42; // Integer bir değerde hata oluşturur.
+throw true; // Boolean bir ifade de hata oluşturur.
+throw new Error('Required'); // `Required` adıyla bir hata nesnesi oluşturur.
+</pre>
+
+<p>Also note that the <code>throw</code> statement is affected by <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion">automatic semicolon insertion (ASI)</a> as no line terminator between the <code>throw</code> keyword and the expression is allowed.</p>
+
+<h2 id="Örnek">Örnek</h2>
+
+<h3 id="İstisna_Nesnesi_Örneği">İstisna Nesnesi Örneği</h3>
+
+<p>Bir istisna atarken bir nesne belirtebilirsiniz. Daha sonra nesnenin özelliklerini <code>catch </code>bloğuna referansta bulabilirsiniz. Aşağıdaki örnek, <code>UserException </code>türünde bir nesne oluşturur ve bunu bir <code>throw </code>ifadesinde kullanır.</p>
+
+<pre class="brush: js notranslate">function UserException(message) {
+ this.message = message;
+ this.name = 'UserException';
+}
+function getMonthName(mo) {
+ mo = mo - 1; // Dizi içinde bir ay sayısı belirlenir (1 = Jan, 12 = Dec)
+ var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
+ 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+ if (months[mo] !== undefined) {
+ return months[mo];
+ } else {
+ throw new UserException('InvalidMonthNo');
+ }
+}
+
+try {
+ // try bloğu
+ var myMonth = 15; // Bir yılda 15 ay bulunmaz.
+ var monthName = getMonthName(myMonth);
+} catch (e) {
+ monthName = 'unknown';
+ console.log(e.message, e.name); // catch bloğuna hata nesnesinin parametreleri giriliyor.
+}
+</pre>
+
+<h3 id="Bir_istisnayı_atmanın_başka_bir_örneği">Bir istisnayı atmanın başka bir örneği</h3>
+
+<p>Aşağıdaki örnek, ABD posta kodu için bir giriş dizesini sınar. Posta kodu geçersiz bir format kullanıyorsa, throw ifadesi bir nesne türü oluşturarak bir istisna atar .</p>
+
+<p>​​​​​​<code>ZipCodeFormatException</code>.</p>
+
+<pre class="brush: js notranslate">/*
+ * Zip Kodu objesi oluşturulur.
+ *
+ * Kabul edilen zip kodları:
+ * 12345
+ * 12345-6789
+ * 123456789
+ * 12345 6789
+ *
+ * parametre kabul edilen zip kodlara uygun değilse
+ * bir istisna atılır.
+ */
+
+function ZipCode(zip) {
+ zip = new String(zip);
+ pattern = /[0-9]{5}([- ]?[0-9]{4})?/;
+ if (pattern.test(zip)) {
+ // zip kodu değeri dizideki ilk eşleşme olacak
+ this.value = zip.match(pattern)[0];
+ this.valueOf = function() {
+ return this.value
+ };
+ this.toString = function() {
+ return String(this.value)
+ };
+ } else {
+ throw new ZipCodeFormatException(zip);
+ }
+}
+
+function ZipCodeFormatException(value) {
+ this.value = value;
+ this.message = 'bir posta kodu için beklenen değerlerle uyuşmuyor';
+ this.toString = function() {
+ return this.value + this.message;
+ };
+}
+
+/*
+ * Zip kodlarını doğrulayan bir komut bloğu olabilir.
+ */
+
+const ZIPCODE_INVALID = -1;
+const ZIPCODE_UNKNOWN_ERROR = -2;
+
+function verifyZipCode(z) {
+ try {
+ z = new ZipCode(z);
+ } catch (e) {
+ if (e instanceof ZipCodeFormatException) {
+ return ZIPCODE_INVALID;
+ } else {
+ return ZIPCODE_UNKNOWN_ERROR;
+ }
+ }
+ return z;
+}
+
+a = verifyZipCode(95060); // 95060
+b = verifyZipCode(9560); // -1
+c = verifyZipCode('a'); // -1
+d = verifyZipCode('95060'); // 95060
+e = verifyZipCode('95060 1234'); // 95060 1234
+</pre>
+
+<h3 id="Bir_istisnayı_tekrar_atmak">Bir istisnayı tekrar atmak</h3>
+
+<p>Hatayı yakaladıktan sonra bir özel durumu geri almak için <code>throw </code>kullanabilirsiniz. Aşağıdaki örnek,</p>
+
+<p>Seğer 50'nin üzerindeyse onu yeniden kullanır. Yeniden biçimlendirilmiş istisna, kullanıcının onu görebilmesi için kapama işlevine veya en üst düzeye kadar çoğalır..</p>
+
+<pre class="brush: js notranslate">try {
+ throw n; // integer bir değerde istisna atar
+} catch (e) {
+ if (e &lt;= 50) {
+ // değer 1 ile 50 arasında ise
+ } else {
+ // tekrar bir istisna atar
+ throw e;
+ }
+}
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>
+ <p>Başlangıç</p>
+
+ <p>Javascript 1.4</p>
+ </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-12.13', 'throw statement')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-throw-statement', 'throw statement')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-throw-statement', 'throw statement')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("javascript.statements.throw")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch"><code>try...catch</code></a></li>
+</ul>